FindFieldとDictionary


一回あたりは大したことないけどやはり遅い。
FindField:10910
Dictionary:278

10,000,000

using (ComReleaser com = new ComReleaser())
{ 
	IMapDocument mapDoc = new MapDocumentClass();
	com.ManageLifetime(mapDoc);

	mapDoc.Open(@"c:\jpn.mxd");

	var map = mapDoc.get_Map(0);
	var featureLayer = (IFeatureLayer)map.get_Layer(0);
	var fc = featureLayer.FeatureClass;

	var loopCount = 10000000;
	var fieldName = "SIKUCHOSON";

	Dictionary<string,int> fieldMap = new Dictionary<string,int>(){
				{ fieldName, fc.FindField(fieldName) }
	};

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

	for (int i = 0; i < loopCount; i++)
	{
		var finx = fc.FindField(fieldName);
	}//end loop

	spWatch.Stop();
	Console.WriteLine("FindField:{0}", spWatch.ElapsedMilliseconds);
	spWatch.Restart();

	for (int i = 0; i < loopCount; i++)
	{
		var finx = fieldMap[fieldName];
	}//end loop

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