ArcObjects Performance Notebook

1. Get Count

// Slow
IQueryFilter queryFilter = new QueryFilter();
queryFilter.WhereClause = "1=1";
featureClass.FeatureCount(queryFilter);

// Fast
featureClass.FeatureCount(null);

2. Search Cursor

IFeatureClass junctionFeatureClass = junctionFeatureLayer.FeatureClass;
int junctionCount = GetFeatureClassCount(junctionFeatureClass);

message = $"Junctions Count: {junctionCount}.";
Output(message);

int idxStatus = junctionFeatureClass.FindField("Status");
message = $"Junctions Status Field Index: {idxStatus}.";
Output(message);

int processJunctionCount = 0;

// Slow
IFeatureCursor featureCursor = junctionFeatureClass.Search(null, false);

// Fast
IFeatureCursor featureCursor = junctionFeatureClass.Search(null, true);

IFeature junctionFeature = null;
while ((junctionFeature = featureCursor.NextFeature()) != null)
{
	processJunctionCount++;
	if (processJunctionCount % 10000 == 0)
	{
		message = $"Process Junctions count: {processJunctionCount}.";
		Output(message);
	}
}


Slow
FeatureClass.Search(null, false)

8/25/2019 11:41:03 AM  Junctions Count: 2819674.
8/25/2019 11:41:03 AM  Junctions Status Field Index: 3.
8/25/2019 11:41:38 AM  Process Junctions count: 10000.
8/25/2019 11:42:27 AM  Process Junctions count: 20000.
8/25/2019 11:43:06 AM  Process Junctions count: 30000.
8/25/2019 11:43:43 AM  Process Junctions count: 40000.
8/25/2019 11:44:34 AM  Process Junctions count: 50000.
......
8/25/2019 12:39:25 PM  Process Junctions count: 750000.
8/25/2019 12:40:00 PM  Process Junctions count: 760000.
8/25/2019 12:40:40 PM  Process Junctions count: 770000.
8/25/2019 12:41:36 PM  Process Junctions count: 780000.
8/25/2019 12:42:16 PM  Process Junctions count: 790000.
8/25/2019 12:42:58 PM  Process Junctions count: 800000.
8/25/2019 12:43:33 PM  Process Junctions count: 810000.
8/25/2019 12:44:12 PM  Process Junctions count: 820000.
8/25/2019 12:44:52 PM  Process Junctions count: 830000.
......

Fast
FeatureClass.Search(null, true)

8/25/2019 12:52:07 PM  Junctions Count: 2819674.
8/25/2019 12:52:07 PM  Junctions Status Field Index: 3.
8/25/2019 12:52:38 PM  Process Junctions count: 10000.
8/25/2019 12:53:10 PM  Process Junctions count: 20000.
8/25/2019 12:53:41 PM  Process Junctions count: 30000.
8/25/2019 12:54:11 PM  Process Junctions count: 40000.
8/25/2019 12:54:42 PM  Process Junctions count: 50000.
......
8/25/2019 1:52:16 PM  Process Junctions count: 1830000.
8/25/2019 1:52:32 PM  Process Junctions count: 1840000.
8/25/2019 1:52:47 PM  Process Junctions count: 1850000.
8/25/2019 1:53:04 PM  Process Junctions count: 1860000.
8/25/2019 1:53:23 PM  Process Junctions count: 1870000.
8/25/2019 1:53:40 PM  Process Junctions count: 1880000.
8/25/2019 1:53:57 PM  Process Junctions count: 1890000.
8/25/2019 1:54:14 PM  Process Junctions count: 1900000.
8/25/2019 1:54:29 PM  Process Junctions count: 1910000.
8/25/2019 1:54:47 PM  Process Junctions count: 1920000.
......
8/25/2019 2:12:40 PM  Process Junctions count: 2800000.
8/25/2019 2:12:57 PM  Process Junctions count: 2810000.

Cost Time: 1 hr 20 mins  ~  2,819,674 records.

######################

Recycling cursors offer performance advantages, 
but they should only be used for reading data, not for writing. 
Recycling cursors allocate a single row object and rehydrate it on each fetch. 
They can be used to optimize read-only access

 

你可能感兴趣的:(ArcObjects,GIS)