I have done this in the past for python scripts using a combination of function decorators and a timing function.
Basically, the timer is placed in a function wrapper that captures information about the script name, function name and execution time. This information is stored in an array until the writePerformance function is called to write the data out to a file.
#xyzGlobals.py
import time
import inspect
#Performance Information
timings = []
def recordPerformance(func):
def wrapper(*arg):
t1 = time.clock()
res = func(*arg)
t2 = time.clock()
timings.append('%s, %s, %0.2f' % (getFilename(func) , func.func_name, (t2-t1)))
return res
return wrapper
def getFilename(func):
try:
return inspect.getfile(func)
except Exception, e:
return ''
def writePerformance(path):
f = open(path, 'w')
f.write('Filename, Function, Seconds\n')
for t in timings:
f.write('{0}\n'.format(t))
f.close()
Then you can use python function decorators to call the timer:
@xyzGlobals.recordPerformance
def makeBasinTable(self):
"""Make the basin tables
"""
src = self.__getDataSource('Basins')
if src != None:
task = BasinCalc(self.log, self.cleanup)
task.setDataSource(src)
task.calcStatistics(self.aoi_obj)
When your script has completed call the xyzGlobals.writePerformance function to write the performance data to a file.
Please note that this code was used for a project undertaken several years ago and hasn't been used recently. However, you should be able to update parts of it as required. You would also need to modify the writePerformance function to print information to ArcMap output instead of a file.