AlgoViz

Estimates in perspective

easy 24 min

The reference numbers behind every estimate: how long memory, disks and networks take, how big common data is, how to turn days into seconds, and the powers of two.

See it run

The reference numbers, stretched until they can be felt, and what each gap decides.

Operations

The latency ladder

From the processor's cache to the other side of the world.

Step 1 of 6

L1 cache

PlaceReal timeIf L1 took 1 second
L1 cache0.5 ns1 second
L2 cache
Memory
SSD
Hard disk seek
Across continents

0.5 ns. Let us call it one second.

Step 1: L1 cache

NS = {"L1": 0.5, "L2": 7, "memory": 100,      "SSD": 150_000, "disk seek": 10_000_000,      "ocean": 150_000_000}def stretched(ns):    return ns / 0.5          # seconds, if L1 took one
Scale
0.5 ns to 150 ms
You leave with
The size of each gap

Remember nanoseconds, then 100 ns, 100 µs, 100 ms: each is a thousand times the last.

In the real world

The same estimates in perspective doing real jobs. Pick one and step through it.

An order page is quick for the team and slow for customers abroad.

Step 1 of 4

In the office

Our system0.5 msUserAPI serverDatabasesame zone
Of a 3 second budget
6 ms

Works for us

12 reads one after another, 0.5 ms each: 6 ms.

Step 1: In the office

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Counting queries, not trips

    critical

    A query of 1 ms behind a trip of 69 ms costs 70. Optimising the query saves almost nothing.

    Wrong
    for item in items:    load(item)              # 40 trips
    Right
    load_many(items)            # 1 trip
  • Reading µs as ms

    major

    One wrong prefix is a factor of a thousand: an SSD looks like a hard disk, or a cache like a database.

    Wrong
    ssd_ms = 100
    Right
    ssd_ms = 0.1                # 100 µs
  • Trusting a 2009 number for a 2026 machine

    minor

    Bulk reads and SSDs are several times quicker now. Use the table for ratios and measure the rest.

    Wrong
    assert read_1mb_ssd_ms == 1
    Right
    measure()                   # then plan
  • Using one latency as a percentile

    major

    The table describes one quiet operation. Under load requests wait, and the slowest few wait longest.

    Wrong
    p99 = db_latency
    Right
    p99 = load_test().p99

Interview tips

  • How to explain it

    • Rules of thumb for how long and how big.
    • Ratios matter, digits do not.
    • Distance is the one that stays.
  • Memory trick

    • 100 ns memory, 100 µs SSD, about 100 ms ocean.
    • L1, L2, RAM, SSD, HDD, network.
    • Ten doublings are a thousand.
  • Reach for it when

    • Choosing memory, disk or network.
    • Counting calls between regions.
    • Choosing the width of an id.
  • Be careful with

    • Bits and bytes.
    • GB and GiB in limits and bills.
    • Averages where the slowest matter.