[GIS] Why does tool take longer to run when in Python script

arcgis-10.0arcmaparcpypython-2.6spatial-analyst

I have written a python script that does some euclidean allocation. For that I use arcpy.gp.EucAllocation_sa() method. Now, my python script takes 30-40% extra time than spatial analyst euclidean allocation tool.

    arcpy.gp.EucAllocation_sa(in_raster_name, out_allocation_raster_name, "", "", cellSize, "VALUE", out_distance_raster_name, "")

Question:

Is there any process that help me to improve the running time of this method? Is there any environment setting issue?

Best Answer

I know where I work, simply typing 'import arcpy' into IDLE or a python command line will take 1-2 minutes. I'm not sure everything that goes on behind the scenes, but I imagine it has a lot of code/libraries to load and it has to check your license. When you run the tool inside of Arc, whether through the Arc python command line or the arc toolbox, or model builder, ArcGIS is already loaded, so that overhead is not there.

Does your C# process run the python script multiple times? If so, there is overhead in importing the arcpy libraries when using python outside of ArcGIS, so if you are running the script multiple times I would imagine you would incur that additional overhead multiple times.