""total time to run func(reps times returns (total timelast result""repslist list(range(reps)start timer(for in repslistret func(*pargs**kargselapsed timer(start return (elapsedretdef bestof(repsfunc*pargs**kargs)""quickest func(among reps runs returns (best timelast result""best * for in range(reps)start timer(ret func(*pargs**kargselapsed timer(start if elapsed bestbest elapsed return (bestrethoist outequalize or perf_counter/other in years seems large enough range usage not timed here or call total(with reps= or add to list and take min(def bestoftotal(reps reps func*pargs**kargs)""best of totals(best of reps runs of (total of reps runs of func)""return bestof(reps totalreps func*pargs**kargsoperationallythis module implements both total time and best time callsand nested best of totals that combines the other two in eachit times call to any function with any positional and keyword arguments passed individuallyby fetching the start timecalling the functionand subtracting the start time from the stop time points to notice about how this version addresses the shortcomings of its predecessorpython' time module gives access to the current timewith precision that varies per platform on windows its clock function is claimed to give microsecond granularity and so is very accurate because the time function may be better on unixthis script selects between them automatically based on the platform string in the sys moduleit starts with "winif running in windows see also the sidebar "new timer calls in on page on other time options in and later not used here for portabilitywe will also be timing python where these newer calls are not availableand their results on windows appear similar in in any event the range call is hoisted out of the timing loop in the total functionso its construction cost is not charged to the timed function in python in range is an iterableso this step is neither required nor harmfulbut we still run the result through list so its traversal cost is the same in both and this doesn' apply to the bestof functionsince no range factors are charged to the test' time timing iteration alternatives