程序员应该知道的延迟数

计算机执行一条指令需要多久,到内存中取一个字需要多久(缓存是否击中), 到磁盘读取连续的字需要多久,而磁盘的定位又需要多久。

2001 年

各种操作的时间,以 2001 年夏季,典型配置的 1GHz 个人计算机为标准:

操作 时间
执行单一指令 1 纳秒
从 L1 高速缓存取一个字 2 纳秒
从内存取一个字 10 纳秒
从磁盘取连续存放的一个字 200 纳秒
磁盘寻址并取字 8 毫秒

Approximate timing for various operations on a typical PC:

operation time
execute typical instruction 1/1,000,000,000 sec = 1 nanosec
fetch from L1 cache memory 0.5 nanosec
branch misprediction 5 nanosec
fetch from L2 cache memory 7 nanosec
Mutex lock/unlock 25 nanosec
fetch from main memory 100 nanosec
send 2K bytes over 1Gbps network 20,000 nanosec
read 1MB sequentially from memory 250,000 nanosec
fetch from new disk location (seek) 8,000,000 nanosec
read 1MB sequentially from disk 20,000,000 nanosec
send packet US to Europe and back 150 milliseconds = 150,000,000 nanosec

在典型PC上各种操作的近似时间:

操作 时间
执行典型指令 1/1,000,000,000 sec = 1 nanosec
从一级缓存中读取数据 0.5 nanosec
分支预测错误 5 nanosec
从二级缓存中读取数据 7 nanosec
互斥锁定/解锁 25 nanosec
从主存储器中读取数据 100 nanosec
通过 1Gbps 网络发送 2K 字节 20,000 nanosec
从内存顺序读取 1MB 数据 250,000 nanosec
从新磁盘位置读取数据(定位) 8,000,000 nanosec
从磁盘顺序读取 1MB 数据 20,000,000 nanosec
在美国向欧洲发送包并返回 150 milliseconds = 150,000,000 nanosec

1985~2015 年

1985~2015 年随着硬件设备的进展,访问延时的变化

The gap between disk, DRAM, and CPU speeds

Figure 1: The gap between disk, DRAM, and CPU speeds

2020 年

Latency Numbers Every Programmer Should Know

Figure 2: Latency Numbers Every Programmer Should Know

扫描二维码关注公众号,回复: 10903498 查看本文章

参考

徐宥 十年学会程序设计

王达 内存与缓存

Peter Norvig Teach Yourself Programming in Ten Years

Computer Systems: A Programmer's Perspective, 3/E (CS:APP3e) Figure 6.16: The gap between disk, DRAM, and CPU speeds.

Colin Scott Latency Numbers Every Programmer Should Know

Wikipedia Hard disk drive performance characteristics

猜你喜欢

转载自www.cnblogs.com/clipboard/p/12723753.html