Home About Podcast Blog Contact

Mag Latency

Every so often a post goes around the software engineering community entitled “Numbers every computer/software engineer should know”, which is a list of the latencies of some common computer operations. The idea is that any software person should have internalized, for example, that reading a value from main memory is 100x slower than reading from L1 cache.

This is a good practice in general, to know the orders of magnitude of operations. But the information is presented like this:

Latency Comparison Numbers (~2012)
    ----------------------------------
    L1 cache reference                           0.5 ns
    Branch mispredict                            5   ns
    L2 cache reference                           7   ns                      14x L1 cache
    Mutex lock/unlock                           25   ns
    Main memory reference                      100   ns                      20x L2 cache, 200x L1 cache
    Compress 1K bytes with Zippy             3,000   ns        3 us
    Send 1K bytes over 1 Gbps network       10,000   ns       10 us
    Read 4K randomly from SSD*             150,000   ns      150 us          ~1GB/sec SSD
    Read 1 MB sequentially from memory     250,000   ns      250 us
    Round trip within same datacenter      500,000   ns      500 us
    Read 1 MB sequentially from SSD*     1,000,000   ns    1,000 us    1 ms  ~1GB/sec SSD, 4X memory
    Disk seek                           10,000,000   ns   10,000 us   10 ms  20x datacenter roundtrip
    Read 1 MB sequentially from disk    20,000,000   ns   20,000 us   20 ms  80x memory, 20X SSD
    Send packet CA->Netherlands->CA    150,000,000   ns  150,000 us  150 ms

This is trying to show the order of magnitude differences between these operations, but it’s still just a bunch of facts to memorize. The actual timings are highly dependent on the specific computer system and year. A mutex lock took 25 nanoseconds in 2012? Is that still true? Does it matter?

On the other hand, the Mag Latency scale is less precise, but more stable. These numbers have gone down over the decades, but notably some of them not that much–a main memory reference on the Apple II took ^-6 time (1µs) in 1977, and ^-7 in 2012.

And when these mag numbers do change, especially relative to one another, it’s a big deal.