Skip to content

Instantly share code, notes, and snippets.

@dagnelies
Created November 25, 2020 08:58
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 dagnelies/eae73f7341ef00068c3d27cd488f33bc to your computer and use it in GitHub Desktop.
Save dagnelies/eae73f7341ef00068c3d27cd488f33bc to your computer and use it in GitHub Desktop.
LMDB vs Pysos benchmark
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