aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark_mini.py
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-05-14 12:25:52 +0300
committerJan Tuomi <jan@jantuomi.fi>2025-05-14 12:25:52 +0300
commit4b42039d22008dd65a1bb176d1b80e167b4d76a2 (patch)
treecc7ac8af3ee3e49836724feb496c8382c7b48e56 /benchmark_mini.py
parent7fdc3a0403fb542616fca1626657eb826ac5b2f6 (diff)
Add and improve benchmark scripts
Diffstat (limited to 'benchmark_mini.py')
-rw-r--r--benchmark_mini.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/benchmark_mini.py b/benchmark_mini.py
new file mode 100644
index 0000000..ece0ea1
--- /dev/null
+++ b/benchmark_mini.py
@@ -0,0 +1,34 @@
+import time
+import tempfile
+import shutil
+from femtoqueue import FemtoQueue
+
+def benchmark_femtoqueue(num_tasks: int = 1000):
+ tmpdir = tempfile.mkdtemp()
+ queue = FemtoQueue(data_dir=tmpdir, node_name="node1")
+
+ data = b"x" * 100 # 100-byte payload
+
+ print(f"Pushing {num_tasks} tasks...")
+ start = time.time()
+ for _ in range(num_tasks):
+ queue.push(data)
+ push_duration = time.time() - start
+ print(f"Pushed in {push_duration:.4f}s ({num_tasks / push_duration:.2f} tasks/sec)")
+
+ print("Processing tasks (pop + done)...")
+ start = time.time()
+ processed = 0
+ while True:
+ task = queue.pop()
+ if not task:
+ break
+ queue.done(task)
+ processed += 1
+ process_duration = time.time() - start
+ print(f"Processed in {process_duration:.4f}s ({processed / process_duration:.2f} tasks/sec)")
+
+ shutil.rmtree(tmpdir)
+
+if __name__ == "__main__":
+ benchmark_femtoqueue(1000)