aboutsummaryrefslogtreecommitdiff
path: root/scripts/performance/timeit_gn2.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_gn2.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_gn2.py')
-rw-r--r--scripts/performance/timeit_gn2.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/performance/timeit_gn2.py b/scripts/performance/timeit_gn2.py
new file mode 100644
index 00000000..1c64e22c
--- /dev/null
+++ b/scripts/performance/timeit_gn2.py
@@ -0,0 +1,54 @@
+import sys
+import timeit
+
+
+print(timeit.timeit(
+"""
+class UserSessionSimulator():
+ def __init__(self, user_id):
+ self._user_id = user_id
+
+ @property
+ def user_id(self):
+ return self._user_id
+
+
+def dump_sample_data(dataset_name, trait_id):
+ with database_connection() as conn, conn.cursor() as cursor:
+ sample_data = {"headers": ["Name", "Value", "SE"], "data": []}
+
+ with app.app_context():
+ g.user_session = UserSessionSimulator(None)
+ data = show_trait.ShowTrait(
+ cursor, user_id=None,
+ kw={
+ "trait_id": trait_id,
+ "dataset": dataset_name
+ }
+ )
+ attributes = data.js_data.get("attributes")
+ for id_ in attributes:
+ sample_data["headers"].append(attributes[id_].name)
+ for sample in data.js_data.get("sample_lists")[0]:
+ sample_data["data"].append(
+ [
+ sample.name,
+ sample.value or 'x',
+ sample.variance or 'x',
+ *[str(sample.extra_attributes.get(str(key), "x"))
+ for key in attributes],
+ ])
+ return sample_data
+
+print(dump_sample_data("HLCPublish", "10001"))
+""",
+ setup="""
+# Required Evils!
+from flask import g
+from wqflask import app
+
+from wqflask.database import database_connection
+from wqflask.show_trait import show_trait
+""",
+ number=int(sys.argv[1])
+))