Has anyone studied the difference in running a Python script in ArcToolbox versus as a stand-alone script? I had to write a quick-and-dirty script to convert a set of RGB images to single band by extracting band 1. As a stand-alone script reading and writing to my PC it processes 1000 identically-sized images in about 350 seconds. Running the same script from ArcToolbox takes about 1250 seconds.
import arcpy
import csv
from os import path
arcpy.env.workspace = in_folder
image_list = arcpy.ListRasters()
#Create a CSV file for timing output
with open(outfile, 'wb') as c:
cw = csv.writer(c)
cw.writerow(['tile_name', 'finish_time'])
#Start the timer at 0
start_time = time.clock()
for image in image_list:
#Extract band 1 to create a new single-band raster
arcpy.CopyRaster_management(path.join(image, 'Band_1'), path.join(out_folder, image))
cw.writerow([image, time.clock()])
I added some code to track when each tile finishes processing, and export the results as a CSV. Converting the finish time to processing time occurs in Excel. Graphing the results, the processing time is roughly the same for each tile as a script, but processing time increases linearly when run as an ArcGIS Tool.
If the data reads and writes are to a network device, the increase appears to be exponential.
I'm not looking for alternate ways to accomplish this particular task. I want to understand why the performance of this script degrades over time when run as an ArcGIS tool, but not as a stand-alone script. I have noticed this behavior with other scripts as well.