Skip to content

Instantly share code, notes, and snippets.

Lets multiply all these durations by a billion:

Magnitudes:

Minute:

L1 cache reference                  0.5 s         One heart beat (0.5 s)
Branch mispredict                   5 s           Yawn
L2 cache reference                  7 s           Long yawn
Mutex lock/unlock                   25 s          Making a coffee
@mjt0704
mjt0704 / latency.markdown
Created March 19, 2014 09:32
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@mjt0704
mjt0704 / BSCrashNotifier
Created March 19, 2014 09:22
about BSCrashNotifier
//BSCrashNotifier is a bundle that allows you to be notified when your app is crashing.
NSBundle* bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"BSCrashNotifier" ofType:@"bundle"]];
Class crashNotifierClass = [bundle principalClass];
if (crashNotifierClass)
{
[crashNotifierClass onCrashSend:@selector(weCrashed:) to:self];
}
else
{
NSLog(@"couldn't load bundle");