Skip to content

Instantly share code, notes, and snippets.

@kofemann
Last active September 21, 2018 13:01
Show Gist options
  • Save kofemann/4744840 to your computer and use it in GitHub Desktop.
Save kofemann/4744840 to your computer and use it in GitHub Desktop.
Latency Comparison Numbers.
#!/usr/bin/env python
"""
Latency Comparison Numbers
If L1 access where a one second
based on number from https://gist.github.com/jboner/2841832
"""
CPU_CYCLE = 0.3 # level 1 cache access latency in nanos
lmap = {
"CPU cycle" : CPU_CYCLE,
"L1 cache reference" : 0.5 ,
"Branch mispredict" : 5 ,
"L2 cache reference" : 7 ,
"Mutex lock/unlock" : 25 ,
"Main memory reference" : 100 ,
"Compress 1K bytes with Zippy" : 3000 ,
"Send 1K bytes over 1 Gbps network" : 10000 ,
"Read 4K randomly from SSD" : 150000 ,
"Read 1 MB sequentially from memory" : 250000 ,
"Round trip within same datacenter" : 500000 ,
"Read 1 MB sequentially from SSD" : 1000000 ,
"Disk seek" : 10000000 ,
"Read 1 MB sequentially from disk" : 20000000 ,
"Send packet CA->Netherlands->CA" : 150000000 ,
"NFS request timeout" : 30000000000,
"LTO4 Tape seek/access time" : 55000000000 ,
}
from datetime import timedelta
DAYS_IN_YEAR = 365
def toHumanString(t):
if abs(t.days) > DAYS_IN_YEAR :
years = t.days / DAYS_IN_YEAR
return "%d years, %s" % (years, str( t - timedelta(days=years*DAYS_IN_YEAR)) )
else:
return str(t)
for k, value in sorted(lmap.iteritems(), key=lambda (k,v): (v,k)):
latency = timedelta(seconds=value/CPU_CYCLE)
print "%-36s : %s" % (k, toHumanString(latency))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment