原创: http://www.imet.me/post/2018/06-30_about_cpu/

关于 CPU 运行的有多快呢,CPU 执行一条命令需要多长时间,CPU,L1,L2,内存,硬盘时间上的差距呢

CPU 内存等硬件时间表格

硬件 时间(ns) 转换时间
cpu 0.38ns
L1 0.5ns
分支预测错误 5ns
L2 7ns
互斥锁加锁 25ns
内存寻址 100ns
上下文切换 1500ns 1.5µs
zippy压缩 1KB 数据 3,000ns 3µs
1Gps网络发送 2KB 数据 20,000ns 20µs
SSD 随机读 150,000ns 150µs
从内存中读取 1MB 的连续数据 250,000ns 250us
同一个数据中心跑一个来回 500,000ns 0.5ms
从 SSD 读取 1MB 的顺序数据 1,000,000ns 1ms
磁盘寻址时间为 10,000,000ns 10ms
从世界上不同城市网络上走一个来回 150,000,000ns 150ms (参考ping报文)

mac cpu,L1,L2

命令行查看 cpu 相关信息

$ sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz

$ system_profiler SPHardwareDataType
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro11,4
      Processor Name: Intel Core i7
      Processor Speed: 2.2 GHz
      Number of Processors: 1
      Total Number of Cores: 4
      L2 Cache (per Core): 256 KB
      L3 Cache: 6 MB
      Memory: 16 GB
      Boot ROM Version: MBP114.0183.B00
      SMC Version (system): 2.29f24
      Serial Number (system): xxxxxxxx
      Hardware UUID: xxxxxxxxxxxx

相关问题

1. 为什么 CPU 时钟频率不能再提高 ?

可以参考链接知乎上的链接,了解一下 CPU 为啥时钟频率不能再提高,总体来说是受到现在制成工艺的限制

2. L1,L2,L3 的结构

顺便看一下 L1, L2, L3 的结构:
关于CPU的一些知识

可以参考链接,了解缓存寻址时间

3. CPU 常说4核8线程是啥?

Intel CPU 通过超线程,实现了一个 CPU 核心跑 2 个线程,来模拟 2 个 CPU 核心。

  • 物理核数量 = CPU 数(机子上装的 CPU 的数量) * 每个 CPU 的核心数
  • 上图也描述了一个 CPU core 里面 2个线程

所以一般 4 核就是 8 CPU 线程来最大化 CPU 的利用率,可以参考超线程多线程相关的介绍

4. CPU 运算速度用什么来衡量?

IPS: Instructions Per Second,每秒指令次数
MIPS: Million Instructions Per Second,每秒百万指令次数

MIPS 是衡量 CPU 运算速度的一个标准

看来要补 cs 课程了

参考

  1. 让 CPU 告诉你硬盘和网络到底有多慢
  2. What Every Programmer Should Know About Memory
  3. Latency numbers every programmer should know
  4. Latency Numbers(by year) Every Programmer Should Know
  5. Getting Physical With Memory
  6. how long does it take to make context
  7. How do I identify which CPU a MacBook uses?
  8. i7-4770HQ
  9. Why haven’t CPU clock speeds increased in the last 5 years?
  10. 理解 CPU Cache
  11. 为什么 CPU 主频很难超过 4GHz?
  12. 每秒指令
  13. Intel 超线程
  14. Multithreading (computer architecture)
  15. 超线程
  16. 认识cpu、核与线程

相关文章: