Created
September 9, 2019 15:49
-
-
Save 1st1/be5a1c10aceb0775d0406e879cf87344 to your computer and use it in GitHub Desktop.
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
import pyrsistent | |
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() | |
pm = pyrsistent.m() | |
for i in range(N): | |
h = h.set(str(i), i) | |
pm = pm.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" immutables.Map:\t\t{end:.4f}s") | |
st = time.monotonic() | |
for _ in range(I): | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm.get(KEY) | |
pm2 = pm.set('aaa', 'aaa') | |
end = time.monotonic() - st | |
print(f" PMap:\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
Benchmark results:
OS: Arch Linux 5.3.0
CPU: Intel i5-4460
RAM: 16G