Skip to content

Instantly share code, notes, and snippets.

@brendanberg
Created January 3, 2012 20: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 brendanberg/1556862 to your computer and use it in GitHub Desktop.
Save brendanberg/1556862 to your computer and use it in GitHub Desktop.
Evil dictionary insertions in Python
from time import time
def elapsed(fn):
t = time()
fn()
return time() - t
def insert_good(n):
for i in range(2 ** n):
d[i] = 0
def insert_evil(n):
for i in range(2 ** n):
d[2 ** i] = 0
d = {}
elapsed(insert_good(14)) # 0.006814002990722656
d = {}
elapsed(insert_evil(14)) # 1.0491819381713867
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment