我的任务是生成多个Polygon,Polygon由PointCollection添加点而生成。经过测试,以下代码在release调试过程耗时3.74秒,在执行exe时,耗时5.68秒。
Stopwatch pStw = new Stopwatch();
pStw.Start(); pStw.Stop();
IPoint pPoint = null;
IPointCollection pPointCollection = null;
List<IPolygon> pPolygonSet = new List<IPolygon>();
pStw.Restart();
for (int i = 0; i < 10000; i++)
{
pPointCollection = new ESRI.ArcGIS.Geometry.Polygon() as IPointCollection;
pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.PutCoords(i,0);
pPointCollection.AddPoint(pPoint);
pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.PutCoords(i+1,0);
pPointCollection.AddPoint(pPoint);
pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.PutCoords(i+1,1);
pPointCollection.AddPoint(pPoint);
pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.PutCoords(i,1);
pPointCollection.AddPoint(pPoint);
pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.PutCoords(i,0);
pPointCollection.AddPoint(pPoint);
IPolygon pPolygon = pPointCollection as IPolygon;
pPolygonSet.Add(pPolygon);
}
pStw.Stop();
Console.WriteLine(pStw.Elapsed.TotalSeconds);
Console.ReadKey();
进一步测试发现,问题出现在以下代码(即新建一个IPointCollection接口以及新建一个IPoint接口),以下代码在release调试过程耗时3.538秒,在执行exe时耗时5.882秒。
pPointCollection = new ESRI.ArcGIS.Geometry.Polygon() as IPointCollection;
pPoint = new ESRI.ArcGIS.Geometry.Point();
问题应该不是出在StopWatch测试时间这块。
请问大家,有碰到过这种情况嘛?可能会是什么原因?