Skip to content

Instantly share code, notes, and snippets.

@1st1
Created August 11, 2017 02:18
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 1st1/9004813d5576c96529527d44c5457dcd to your computer and use it in GitHub Desktop.
Save 1st1/9004813d5576c96529527d44c5457dcd to your computer and use it in GitHub Desktop.
HAMT performance micro-bench
import time
I = 1_000_000
KEY = '5'
for N in [5, 10, 20, 30, 100, 200, 300, 400, 500, 1000]:
print('=============')
print(f' # of items: {N}; iterations: {I}')
print()
h = hamt()
d = dict()
for i in range(N):
h = h.set(str(i), i)
d[str(i)] = i
assert len(h) == N
for i in range(N):
assert h.get(str(i), 'not found') == i
st = time.monotonic()
for _ in range(I):
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d2 = d.copy()
d2['aaa'] = 'aaa'
end = time.monotonic() - st
print(f" dict copy:\t\t\t{end:.4f}s")
st = time.monotonic()
for _ in range(I):
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d.get(KEY)
d['aaa'] = 'aaa'
end = time.monotonic() - st
print(f" dict:\t\t\t\t{end:.4f}s")
st = time.monotonic()
for _ in range(I):
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h.get(KEY)
h2 = h.set('aaa', 'aaa')
end = time.monotonic() - st
print(f" hamt:\t\t\t\t{end:.4f}s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment