aboutsummaryrefslogtreecommitdiff
path: root/scripts/performance/timeit_lmdb.py
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-02-03 12:58:13 +0300
committerBonfaceKilz2023-02-03 13:08:35 +0300
commitc7d242233403594d7a5422344a49a16c2c738222 (patch)
tree216ce9923cc103e05790cf6d3ae4d304fb3a6018 /scripts/performance/timeit_lmdb.py
parentceaefbd3022044f13ba2d763598460b83bfa19ee (diff)
downloadgenenetwork2-c7d242233403594d7a5422344a49a16c2c738222.tar.gz
Add perf scripts that compare fetching a trait using GN API vs LMDB
* scripts/performance/(README,org, timeit_gn2.py, timeit_lmdb.py): New files. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'scripts/performance/timeit_lmdb.py')
-rw-r--r--scripts/performance/timeit_lmdb.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/performance/timeit_lmdb.py b/scripts/performance/timeit_lmdb.py
new file mode 100644
index 00000000..17514667
--- /dev/null
+++ b/scripts/performance/timeit_lmdb.py
@@ -0,0 +1,36 @@
+import sys
+import timeit
+
+print(timeit.timeit(
+"""
+PATH = "/home/munyoki/tmp/dataset/HLCPublish/10001/"
+env = lmdb.open(PATH)
+
+BLOB_HASH_DIGEST = 32
+
+# def index_matrix(row_pointers):
+
+with env.begin(write=False) as txn:
+ current_hash = txn.get(b"current")
+ matrix_hash = txn.get(current_hash + b":matrix")
+ row_pointers = txn.get(matrix_hash +
+ b":row-pointers")
+ nrows, = struct.unpack("<Q",
+ txn.get(matrix_hash + b":nrows"))
+ metadata = txn.get(matrix_hash + b":metadata")
+ sample_data = []
+ for i in range(0, (nrows-1)*32, 32):
+ sample_data.append(
+ json.loads(txn.get(row_pointers[i:i+32]).decode())
+ )
+ print(sample_data)
+ print(metadata.decode())
+""",
+ setup="""
+import struct
+import array
+import json
+import lmdb
+""",
+ number=int(sys.argv[1])
+))