Created
November 25, 2020 08:58
-
-
Save dagnelies/eae73f7341ef00068c3d27cd488f33bc to your computer and use it in GitHub Desktop.
LMDB vs Pysos benchmark
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 time | |
import json | |
import os | |
# pip install pysos | |
# pip install chardet | |
import pysos | |
# pip install lmdbm | |
from lmdbm import Lmdb | |
class JsonLmdb(Lmdb): | |
def _pre_key(self, value): | |
return value.encode("utf-8") | |
def _post_key(self, value): | |
return value.decode("utf-8") | |
def _pre_value(self, value): | |
return json.dumps(value).encode("utf-8") | |
def _post_value(self, value): | |
return json.loads(value.decode("utf-8")) | |
N = 100 * 1000 | |
t = time.time() | |
db = JsonLmdb.open("test_lmdb.db", "c") | |
for i in range(N): | |
db["key_" + str(i)] = {"some": "object_" + str(i)} | |
db.close() | |
print('LMDB time:', time.time() - t) | |
# => LMDB time: 413.4471242427826 | |
t = time.time() | |
db = pysos.Dict("test_pysos.db") | |
for i in range(N): | |
db["key_" + str(i)] = {"some": "object_" + str(i)} | |
db.close() | |
print('PYSOS time:', time.time() - t) | |
# => PYSOS time: 4.514040470123291 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment