Skip to content

Instantly share code, notes, and snippets.

@jul
Created June 20, 2012 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jul/2960250 to your computer and use it in GitHub Desktop.
Save jul/2960250 to your computer and use it in GitHub Desktop.
benchmarking fixed size dict
from yahi.fixed_size_dict import *
from time import time
sample=1000000
def time_for(size, constructor):
if constructor==dict:
a=dict()
else:
a=constructor(size)
print "size %d" % size
print "fact %s" % repr(constructor.__name__)
start = time()
for i in range(sample):
a[i]=i
print "took %f" % (time() - start)
for size in [ 10, 100, 1000, 10000]:
for constructor in bmFixedLookupTable, FixedLookupTable,dict:
time_for(size,constructor)
"""size 10
fact 'bmFixedLookupTable'
took 1.424893
size 10
fact 'FixedLookupTable'
took 2.594238
size 10
fact 'dict'
took 0.215046
size 100
fact 'bmFixedLookupTable'
took 1.356977
size 100
fact 'FixedLookupTable'
took 2.579066
size 100
fact 'dict'
took 0.212382
size 1000
fact 'bmFixedLookupTable'
took 1.359531
size 1000
fact 'FixedLookupTable'
took 2.551217
size 1000
fact 'dict'
took 0.213694
size 10000
fact 'bmFixedLookupTable'
took 1.415309
size 10000
fact 'FixedLookupTable'
took 2.686362
size 10000
fact 'dict'
took 0.212665
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment