Skip to content

Instantly share code, notes, and snippets.

@negrinho
Forked from jboner/latency.txt
Created July 16, 2018 21:11
Show Gist options
  • Save negrinho/8a8b45a8958a8653054aa2b349b4cb05 to your computer and use it in GitHub Desktop.
Save negrinho/8a8b45a8958a8653054aa2b349b4cb05 to your computer and use it in GitHub Desktop.
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers Simplified (~2012)
---------------------------------- log2 log10
L1 cache reference 0 0 ~ 1 ns
Branch mispredict 3 1
L2 cache reference 4 1
Mutex lock/unlock 6 2
Main memory reference 8 2
Compress 1K bytes with Zippy 13 4
Send 1K bytes over 1 Gbps network 14 4
Read 4K randomly from SSD* 18 5
Read 1 MB sequentially from memory 19 6
Round trip within same datacenter 20 6
Read 1 MB sequentially from SSD* 21 6
Disk seek 24 7
Read 1 MB sequentially from disk 25 8
Send packet CA->Netherlands->CA 28 9
Notes
-----
The log2 and log10 columns have logarithm computations (rounded to an integer power)
relative to the first item on the list (L1 cache reference). I find that the exact
numbers are not terribly important. It is much simpler to reason about relative
dimensions in this format---simply take two elements in a column and subtract
them. For example, using the log10 column, "Read 1 MB sequentially from memory"
is about 1000000 slower than "L1 cache reference" and 10000 slower than
"Main memory reference". For very rough back-of-the-envelope computations, I often
use 2^10 ~ 10^3 and 2^3 ~ 10^1, e.g., "Send 1K bytes over 1 Gbps network" is about
16000 slower than "L1 cache reference". The logarithms were computed from the
numbers found in https://gist.github.com/jboner/2841832.
@artkpv
Copy link

artkpv commented Jan 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment