question 363 Profiling & Optimization · easy
Summarise a benchmark run
A CI job stores the totals that timeit.repeat returned. Write summarise(totals, number) for its report: the best and worst per-call times and how noisy the run was (the worst round divided by the best).
Function
summarise(totals, number)totalsa non-empty list of round totals in seconds, each for
number callsReturns
{"best": …, "worst": …, "spread": …}: best and worst per-call seconds, and worst total ÷ best totalExamples
callsummarise([0.41, 0.4, 0.52], 1000)returns{'best': 0.0004, 'worst': 0.00052, 'spread': 1.3}
callsummarise([2, 1], 10)returns{'best': 0.1, 'worst': 0.2, 'spread': 2.0}
callsummarise([0.5], 5)returns{'best': 0.1, 'worst': 0.1, 'spread': 1.0}