question 379 Threading & Multiprocessing · hard
A scaling report from benchmark runs
A team benchmarked a CPU-heavy parser on CPython with different numbers of worker processes, several runs each. Write scaling_report(runs): for every worker count, the best time, the speed-up against the best 1-worker time, and the efficiency (speed-up ÷ workers), sorted by worker count.
Simulated: this runs against results recorded on real Python.
Function
scaling_report(runs)runsa list of
{"workers": int, "seconds": float}; there is at least one run with 1 workerReturnsa list of
(workers, best_seconds, speedup, efficiency) tuples sorted by workersExamples
callscaling_report([{'workers': 1, 'seconds': 4}, {'workers': 2, 'seconds': 2.5}, {'workers': 4, 'seconds': 1.6}])returns[(1, 4.0, 1.0, 1.0), (2, 2.5, 1.6, 0.8), (4, 1.6, 2.5, 0.625)]
callscaling_report([{'workers': 1, 'seconds': 2}])returns[(1, 2.0, 1.0, 1.0)]
callscaling_report([{'workers': 1, 'seconds': 3}, {'workers': 1, 'seconds': 2}, {'workers': 2, 'seconds': 1}])returns[(1, 2.0, 1.0, 1.0), (2, 1.0, 2.0, 1.0)]