来源:Latency Numbers Every Programmer Should Know

图片版:

文字版:

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

Notes
-----
1 ns = 10^-9 seconds
1 us = 10^-6 seconds = 1,000 ns
1 ms = 10^-3 seconds = 1,000 us = 1,000,000 ns

中文整理版:

操作耗时备注
CPU一级缓存寻址0.5纳秒
CPU二级缓存寻址7纳秒
互斥锁25纳秒
内存寻址100纳秒
使用zippy压缩1k文件3000纳秒(3微秒)
在1Gbps的网络中发送1k数据10000纳秒(10微秒)
从ssd中随机读取4KB数据150000纳秒(150微秒)SSD速率:1GB/s
从内存中顺序读取1MB250000纳秒(250微秒)
同一数据中心往返耗时500000纳秒(500微秒)
从ssd中随机读取1MB数据1000000纳秒(1000微秒,1毫秒)SSD速率:1GB/s
磁盘寻址10000000纳秒(10000微秒,10毫秒)约等于20次数据中心往返
从磁盘中顺序读取1MB数据20000000纳秒(20000微秒,20毫秒)

备注:1秒=$10^3$毫秒=$10^6$微秒=$10^9$纳秒。

最后修改:2020 年 02 月 03 日
喜欢就给我点赞吧