$ git clone https://github.com/MagicStack/immutables.git
cd immutables
wget https://gist.githubusercontent.com/1st1/57d979e1e58948a7e523754a3d02a57d/raw/8857aca8e0f13c804218540820993b6481cd6619/bench.py
pypy3 bench.py
-- observe the timings for "hamt"- run
pypy3 bench.py
-- observe how "hamt" timings are way worse now find . -name '*.pyc' | xargs rm
- run
pypy3 bench.py
-- observe how "hamt" timings are low again
Last active
April 3, 2018 17:19
-
-
Save 1st1/57d979e1e58948a7e523754a3d02a57d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import immutables | |
import time | |
I = 1000000 | |
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 = immutables.Map() | |
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): | |
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") |
=============
# of items: 5; iterations: 1000000
dict copy: 0.1487s
hamt: 0.6501s
=============
# of items: 10; iterations: 1000000
dict copy: 0.3177s
hamt: 0.6005s
=============
# of items: 20; iterations: 1000000
dict copy: 0.4995s
hamt: 0.7768s
=============
# of items: 30; iterations: 1000000
dict copy: 0.6714s
hamt: 0.9609s
=============
# of items: 100; iterations: 1000000
dict copy: 2.2390s
hamt: 0.9238s
=============
[etc]
=============
# of items: 5; iterations: 1000000
dict copy: 0.1543s
hamt: 3.9164s
=============
# of items: 10; iterations: 1000000
dict copy: 0.3109s
hamt: 6.4567s
=============
# of items: 20; iterations: 1000000
dict copy: 0.4718s
hamt: 6.6128s
=============
[etc]
Python 3.5.3 (3f6eaa010fce, Jan 11 2018, 05:27:47)
[PyPy 5.10.1 with GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
I'm running this all under pypy3 venv created with pypy3 -m venv test
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment