Lesson 1 · Unit 01
Timing
Noise, warm-up, the median, and benchmarks that lie
What you practise
- Wall-clock against CPU time, noise and warm-up, repeat and take the median, what a benchmark really compares, the benchmark that measures the wrong thing
Try a question from this lesson
Pick one
Same function, same input, five runs. Which single number best says how long it takes?
run time
1 31 ms
2 12 ms
3 11 ms
4 48 ms
5 12 msCorrect answer
12 ms, the median
Why
The code did not change between runs, so the spread comes from the machine: a cold start, another program taking the CPU. The median ignores those outliers. The mean lets two bad runs nearly double the number.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Noise and warm-up
Run the same code twice and you get two different times.
The first runs are slow: files are not in memory yet, and the runtime has not optimised the code. That is warm-up.
Later runs still wobble, because the machine is doing other things. That is noise.
So: run it several times, set the warm-up aside, and report the median, the middle value once the timings are sorted.
10 more exercises in the app
- 2× type the answer
- 4× multiple choice
- 1× match the pairs
- 1× true or false
- 1× fill the blanks
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.