Latency numbers
How many memory reads fit in a disk seek? Feel the gaps between cache, memory, disk and network, to the nearest power of ten.
How it plays
Two operations — an L1 cache hit and a main memory reference, a disk seek and a network round trip — and you pick roughly how many times slower the first is, as a power of ten. Or several at once, and you pick the slowest or the fastest. The pairs move closer together as you climb, and the clock tightens.
The figures are Peter Norvig's table of approximate timings on a typical PC (norvig.com/21-days.html). They are order-of-magnitude and dated — "disk" means a spinning disk, and your machine differs — so only ratios are asked, never a value, and a ratio too close to the line between two powers of ten is never asked.
The wrong options are the neighbouring powers of ten: the usual miss is one order of magnitude out. The working divides the two figures.
Keys
Space starts and skips ahead · 1–9 pick · Enter submits · Esc stops. On a phone, tap.
What it trains
This builds a feel for the relative costs in one table of computer timings. Those figures are approximate; it does not tell you what your hardware does.
Learn
How to get better at latency numbers: the method, the techniques, what each new level asks of you, and the traps the wrong answers are made of.
Your approach to each question
- Put both operations on the ladder before you think about the ratio. Say each one’s figure to yourself — “memory, 100 ns; disk seek, 8 ms” — in its own unit.
- Bring both to nanoseconds by counting powers of ten: µs is 10³ ns, ms is 10⁶ ns. 8 ms is 8 × 10⁶ ns.
- Divide the front numbers and subtract the powers. 8 × 10⁶ ÷ 10² is 8 × 10⁴.
- Round on a log scale: if the front number is 3.16 or more, go up a power. 8 × 10⁴ is nearer 10⁵ than 10⁴. Then pick that option.
Techniques and tricks
Learn the ten as one ladder
There are ten operations and you can hold them in order: L1 0.5 ns, branch mispredict 5 ns, L2 7 ns, mutex 25 ns, main memory 100 ns, 2 KB over the network 20 µs, 1 MB from memory 250 µs, disk seek 8 ms, 1 MB from disk 20 ms, US–Europe round trip 150 ms.
Three bands by unit
Everything on the chip is nanoseconds; memory sits at the top of that band at 100 ns. The network send and the memory read are microseconds. The disk and the transatlantic trip are milliseconds. For “which is slowest”, the band settles most questions before the numbers do.
Subtract exponents, then fix the front
Write each time as a number times a power of ten. The power of the ratio is the difference of the powers; the front numbers then nudge it up or down by one.
e.g. seek ÷ memory = 8 × 10⁶ ÷ 1 × 10² = 8 × 10⁴ → about 10⁵
The √10 line
On a log scale the halfway point between 10ⁿ and 10ⁿ⁺¹ is 3.16 × 10ⁿ, not 5 × 10ⁿ. So 4 × 10ⁿ already rounds up. Ratios too close to that line are never asked, so if you are near it, recheck a figure.
e.g. mutex ÷ branch mispredict = 25 ÷ 5 = 5, past 3.16, so about 10¹
Remember a few anchor ratios
Main memory is about 200 times an L1 hit. A disk seek is about 80,000 memory references. A round trip to Europe is about 19 disk seeks. Most other pairs are a short step from one of these.
e.g. round trip ÷ memory = 150 ms ÷ 100 ns = 1,500,000 → about 10⁶
Same size, different medium
Reading 1 MB sequentially takes 250 µs from memory and 20 ms from a spinning disk: 80 times longer, so about 10². Compare like with like and the medium is the whole difference.
As the levels climb
- Three question kinds are mixed from the start: “How many times slower”, “Which is slowest” and “Which is fastest”. The ladder is short and has a real top.
- At first only pairs at least 10³ apart are asked, and in the pick-one questions the answer is at least 100 times away from the rest. Then the pairs close to 10² and a 10× gap, and finally to 10¹ and a 3× gap. Close pairs are where the exact figures matter, so the ladder above stops being enough and you need the numbers.
- The clock tightens three times, to 55%. A ratio question gives 12 seconds at full time; a pick-one gives 5 seconds plus 2.5 for each operation shown. At the tight end you need the figures by heart — there is no time to reason them out.
Traps to avoid
- One power of ten out: the wrong options are the neighbouring powers, 10ⁿ⁻¹ and 10ⁿ⁺¹. It almost always comes from a unit slip — ms taken for µs — so write both in nanoseconds before you subtract.
- Rounding at 5 instead of 3.16: 8 × 10⁴ and 4 × 10⁴ both round up to 10⁵. If you rounded down because the front number was under 5, you rounded on the wrong scale.
- The L1 half-nanosecond: L1 is 0.5 ns, not 1 ns. Ratios against it are twice what you would expect — memory is 200 times L1, not 100.
- Agonising over two close options in a pick-one: the answer is always far from every other option shown — 100 times, then 10, then 3 as you climb. If two options are close, like L2 at 7 ns and the branch mispredict at 5 ns, neither of them is the answer.
- Sequential reads mistaken for small ones: “Read 1 MB sequentially from memory” is 250 µs, slower than sending 2 KB over the network at 20 µs. A big transfer from fast storage can outlast a small one over a slow link.
How to practise
- Untick all but “How many times slower” in “Questions” until the exponent arithmetic is quick, then add “Which is slowest” and “Which is fastest” back.
- Raise “Options shown” to 8. A ratio question then shows more neighbouring powers, and a pick-one shows more operations at once, so you have to place every one of them.
- Read the working after each miss: it gives both figures and the exact ratio, so you see whether you misremembered a figure or misrounded.
- Remember these are one published table for one typical machine of its time. Learn them as a scale of relative costs, not as what your own computer does.
Levels
Each question has a clock that comes from the work it asks for. There are 6 levels with the default settings, and the counter stops at the real top. Your level is judged on your last ten answers, every ten: 90% moves you up, below 80% moves you down, which holds most people near four in five right.
All of it is in the settings beside Start — how many answers a judgement looks at and how often it recalibrates, the thresholds, the time, which questions, how many options, and whether you see each verdict at once or review them together at the judgement. You can also jump to any level.
More computing
All games →Data structures by hand
Push, pop, insert, probe: trace a stack, a queue, a search tree, a heap and a hash table by hand, and say what comes out or what the array holds.What does this query return?
A tiny table, a short SQL query: say what comes back. COUNT(*) or COUNT(x), NULL in a WHERE, LEFT JOIN counts, and NOT IN with a NULL.Race conditions
Two threads each run x = x + 1 twice. Can x end at 2? Work out every value a race can leave — every interleaving is checked by running it.Subnets on sight
Hosts in a /26, the network address of 192.168.10.77/26, the mask of a /20, same subnet or not: IPv4 subnetting, exact, in your head.Binary and hex
Binary to decimal, decimal to hex, hex to binary — convert between the bases a computer is written in, at a width that keeps growing.Bitwise
AND, OR, XOR, NOT, shifts, x AND (x − 1) and two's complement, worked bit by bit at a width that keeps growing.