From 5213d5c240a172f43937144ad6b55ddf57ffc64b Mon Sep 17 00:00:00 2001 From: unexcellent <> Date: Wed, 11 Dec 2024 14:50:06 +0100 Subject: [PATCH] test: add vector benchmark functions --- benchmarking/bench_vector.py | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 benchmarking/bench_vector.py diff --git a/benchmarking/bench_vector.py b/benchmarking/bench_vector.py new file mode 100644 index 0000000..bd3920d --- /dev/null +++ b/benchmarking/bench_vector.py @@ -0,0 +1,44 @@ +import pytest +import numpy as np + +from quantio import Length, Vector + + +def bench_from_numpy__base_unit(benchmark): + f = lambda: Vector.from_numpy(np.ones(100), Length, "meters") + benchmark.pedantic(f, iterations=100, rounds=100) + + +def bench_from_numpy__other_unit(benchmark): + f = lambda: Vector.from_numpy(np.ones(100), Length, "centimeters") + benchmark.pedantic(f, iterations=100, rounds=100) + + +def bench_to_numpy__base_unit(benchmark): + vector = Vector.from_numpy(np.ones(100), Length, "meters") + f = lambda: vector.to_numpy("meters") + benchmark.pedantic(f, iterations=100, rounds=100) + + +def bench_to_numpy__other_unit(benchmark): + vector = Vector.from_numpy(np.ones(100), Length, "meters") + f = lambda: vector.to_numpy("centimeters") + benchmark.pedantic(f, iterations=100, rounds=100) + + +def bench_add(benchmark): + vector1 = Vector.from_numpy(np.ones(100), Length, "meters") + vector2 = Vector.from_numpy(np.ones(100), Length, "meters") + f = lambda: vector1 + vector2 + benchmark.pedantic(f, iterations=100, rounds=100) + + +def bench_sub(benchmark): + vector1 = Vector.from_numpy(np.ones(100), Length, "meters") + vector2 = Vector.from_numpy(np.ones(100), Length, "meters") + f = lambda: vector1 - vector2 + benchmark.pedantic(f, iterations=100, rounds=100) + + +if __name__ == "__main__": + pytest.main([__file__, "-v"])