allowing the repeat count to be passed in as keyword argument named _repsfile timer py ( and ""total(spam = = _reps= calls and times spam( = = _reps timesand returns total time for all runswith final result bestof(spam = = _reps= runs best-of- timer to attempt to filter out system load variationand returns best time among _reps tests bestoftotal(spam = = _rep = reps= runs best-of-totals testwhich takes the best among _reps runs of (the total of _reps runs)""import timesys timer time clock if sys platform[: ='winelse time time def total(func*pargs**kargs)_reps kargs pop('_reps' repslist list(range(_reps)start timer(for in repslistret func(*pargs**kargselapsed timer(start return (elapsedretpassed-in or default reps hoist range out for lists def bestof(func*pargs**kargs)_reps kargs pop('_reps' best * for in range(_reps)start timer(ret func(*pargs**kargselapsed timer(start if elapsed bestbest elapsed return (bestretdef bestoftotal(func*pargs**kargs)_reps kargs pop('_reps ' return min(total(func*pargs**kargsfor in range(_reps )this module' docstring at the top of the file describes its intended usage it uses dictionary pop operations to remove the _reps argument from arguments intended for the test function and provide it with default (it has an unusual name to avoid clashing with real keyword arguments meant for the function being timednotice how the best of totals here uses the min and generator scheme we saw earlier instead of nested callsin part because this simplifies results and avoids minor time overhead in the prior version (whose code fetches best of time after total time has been computed)but also because it must support two distinct repetition keywords with defaults--total and bestof can' both use the same argument name add argument prints in the code if it would help to trace its operation timing iteration alternatives