diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-05-14 00:38:02 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-05-14 01:17:16 +0300 |
| commit | cb57365b211c7178e10f8b722abca3afdb65e206 (patch) | |
| tree | d9ee7c8c55e4f95e5d09acc3938cbe7d156b1333 /benchmark.py | |
| parent | f543c642b9ce0b0785639e1fb8fe9dbf9d41163a (diff) | |
Add initial impl
Diffstat (limited to 'benchmark.py')
| -rw-r--r-- | benchmark.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/benchmark.py b/benchmark.py new file mode 100644 index 0000000..a28dc0d --- /dev/null +++ b/benchmark.py @@ -0,0 +1,34 @@ +import time +import tempfile +import shutil +from femtoqueue import FemtoQueue, FemtoTask + +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(500) |
