Cursor


Python vs ArcObjectsは単純ループでArcObjectsの圧勝? verにもよるのか。Python糞遅い。1万レコード。そして初回時の気持ち悪い遅さ。。
Python (SHAPE@)
8398 ミリ秒
3383 ミリ秒
3687 ミリ秒

Python (“SHAPE@X”, “SHAPE@Y”)
3180 ミリ秒
3937 ミリ秒
2733 ミリ秒

ArcObjects
900 ミリ秒
871 ミリ秒
867 ミリ秒

Python

# -*- coding: cp932 -*-

import arcpy
import time


fc = r"C:\jpn\jpn.gdb\rnd10k"
start = time.time()

with arcpy.da.SearchCursor(fc, "SHAPE@") as cursor:#["SHAPE@X", "SHAPE@Y"]) as cursor:
    for row in cursor:
        shp = row[0]
        
print time.time() - start

ArcObjects

var spWatch = new System.Diagnostics.Stopwatch();
spWatch.Start();

using (ComReleaser com = new ComReleaser())
{
  Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
  IWorkspaceFactory wsf = (IWorkspaceFactory)Activator.CreateInstance(t);
  com.ManageLifetime(wsf);

  IFeatureWorkspace ws = (IFeatureWorkspace)wsf.OpenFromFile(@"C:\jpn\jpn.gdb", 0);
  com.ManageLifetime(ws);

  IFeatureClass fc = ws.OpenFeatureClass("rnd10k");
  com.ManageLifetime(fc);

  IFeatureCursor cursor = fc.Search(null, true);
  com.ManageLifetime(cursor);

  IFeature feature = null;
  while ((feature = cursor.NextFeature()) != null)
  {
  }//end loop

}//end com

spWatch.Stop();
Console.WriteLine(spWatch.ElapsedMilliseconds);
カテゴリー: 開発 タグ: , パーマリンク