luckilypython makes it easy to time code for exampleto get the total time taken to run multiple calls to function with arbitrary positional argumentsthe following firstcut function might sufficefile timer py import time def timer(func*args)start time clock(for in range( )func(*argsreturn time clock(start simplistic timing function total elapsed time in seconds this works--it fetches time values from python' time moduleand subtracts the system start time from the stop time after running , calls to the passed-in function with the passed-in arguments on my computer in python from timer import timer timer(pow timer(str upper'spam' time to call pow( times time to call 'spamupper( times though simplethis timer is also fairly limitedand deliberately exhibits some classic mistakes in both function design and benchmarking among theseitdoesn' support keyword arguments in the tested function call hardcodes the repetitions count charges the cost of range to the tested function' time always uses time clockwhich might not be best outside windows doesn' give callers way to verify that the tested function actually worked only gives total timewhich might fluctuate on some heavily loaded machines in other wordstiming code is more complex than you might expectto be more general and accuratelet' expand this into still simple but more useful timer utility functions we can use both to see how iteration alternative options stack up nowand apply to other timing needs in the future these functions are coded in module file so they can be used in variety of programsand have docstrings giving some basic details that pydoc can display on request--see figure - in for screenshot of the documentation pages rendered for the timing modules we're coding herefile timer py ""homegrown timing tools for function calls does total timebest-of timeand best-of-totals time ""import timesys timer time clock if sys platform[: ='winelse time time the benchmarking interlude