. 引入
- 使用多線程最主要的目的就是縮短應用程序完成任務的時間嗅战。
- 在【為什么需要多線程】總結(jié)中有這樣一句話:<b>若多個線程都是CPU密集型贯溅,那么并不能獲取性能上的提升糕篇。</b>同理,若都是IO密集型的该窗,也不能提升性能弟蚀。即這種情況下,使用多線程不能縮短應用程序完成任務的時間酗失。
- 總結(jié):最好在大量CPU計算(控制)和大量IO共存的時候用义钉。
google2010年ppt
硬件 | 耗時 |
---|---|
L1 cache reference | 0.5ns |
Branch mispredict | 5ns |
L2 cache reference | 7ns |
Mutex lock/unlock | 100ns |
Main memory reference | 100ns |
Send 1M bytes over 1Gbps network | 10ms |
Read 1M sequentially from memory | 0.25ms |
Round trip within data center | 0.5ms |
Disk seek | 8~10ms |
Read 1MB sequentially from disk | 20~25ms |