latency numbers every programmer should know

August 10, 2026

Latency Numbers Every Programmer Should Know

Rough orders of magnitude, not exact values. The point isn't the digits — it's the ratios between tiers: each tier is roughly ~100× slower than the one above it. Cache → RAM → SSD → spinning disk / network. When guessing where time goes, reach for these.

Units: 1 ms = 1,000 µs = 1,000,000 ns.

1. On-CPU — L1/L2 cache & RAM (nanoseconds)

The "free" tier. You live here. Stay here.

OperationLatencyNotes
L1 cache reference0.5 nsbaseline — data already next to the core
Branch mispredict5 nsCPU guessed the wrong `if` branch and had to redo work
L2 cache reference7 ns14× slower than L1
Mutex lock/unlock25 nscost of one lock+unlock when *uncontended* (see note below)
Main memory (RAM) reference100 ns20× slower than L2
Read 4 KB randomly from memory1,000 ns
Read 1 MB sequentially from memory250,000 ns0.25 ms

What's a mutex? A mutex ("mutual exclusion" lock) is the guard that lets only one thread touch shared data at a time. A thread locks it before entering the critical section and unlocks it after, so two threads can't stomp on the same variable at once. The 25 ns above is the fast, uncontended case — nobody else wants the lock, so it's just a couple of atomic CPU instructions. If another thread is already holding it (contended), yours has to wait/sleep and the cost can jump to microseconds or more — orders of magnitude worse. Takeaway: locks are cheap only when threads rarely collide; lots of contention is a real performance problem.

2. Local storage — SSD & spinning disk (microseconds → milliseconds)

Left the chip. Now you're paying real time.

OperationLatencyNotes
Read 4 KB randomly from SSD150,000 ns0.15 ms
Read 1 MB sequentially from SSD1,000,000 ns1 ms · 4× slower than RAM
Disk seek (spinning)10,000,000 ns10 ms · ≈ 20 DC round trips
Read 1 MB sequentially from disk20,000,000 ns20 ms · 80× slower than RAM

3. Over the wire — network (microseconds → hundreds of ms)

Distance is destiny. Local link is cheap; crossing the planet is not.

OperationLatencyNotes
Send 1 KB over 1 Gbps network10,000 ns0.01 ms
Round trip within same datacenter500,000 ns0.5 ms
Packet CA → Netherlands → CA150,000,000 ns150 ms · 15× a disk seek

Bonus — CPU work

Compression sits between RAM and SSD — cheaper than it feels.

OperationLatencyNotes
Compress 1 KB with Zippy3,000 ns0.003 ms

The three ratios worth memorizing

  • Cache → RAM: ~100× (0.5 ns → 100 ns). Stay in cache.
  • RAM → disk seek: ~100,000× (100 ns → 10 ms). Avoid random disk.
  • DC hop → cross-continent: ~300× (0.5 ms → 150 ms). Geography dominates everything.