Created
January 3, 2012 20:49
-
-
Save brendanberg/1556862 to your computer and use it in GitHub Desktop.
Evil dictionary insertions in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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