On my laptop I get;
time python slow.py
The best score 21439.0 comes from pattern MDC053363.000_9241
python slow.py 3.57s user 0.13s system 111% cpu 3.322 total
This shows that the script took 3.322 seconds (so, about 3.3 seconds) to run.
I should repeat this a few times to be sure;
Run 1: 3.334 s
Run 2: 3.218 s
Run 3: 3.266 s
Run 4: 3.274 s
import slow
(ids, varieties, data) = slow.load_and_parse_data(5)
timeit(slow.load_and_parse_data(5))
3.09 ms ± 7.95 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
scores = slow.calculate_scores(data)
timeit(slow.calculate_scores(data))
3.14 s ± 6.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
best_pattern = slow.get_index_of_best_score(scores)
timeit(slow.get_index_of_best_score(scores))
5.39 µs ± 29.7 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
The total runtime of the three functions (about 3.2 seconds) is close to the 3.3 seconds measured in Exercise 1. The difference will be the time it takes for Python to load, import modules, print things to the screen, close down etc.
The slowest function is calculate_scores, which takes ~3.1 seconds.
The script would be 1.5 milliseconds faster is we could double the speed of load_and_parse_data.
The script would be 1.5 seconds(!) faster if we could double the speed of the calculate_scores function.
The script would only be 2.7 microseconds faster if we could double the speed of the get_index_of_best_score function.
We should concentrate our optimisation effort on accelerating the calculate_scores function.