Skip to content

Commit

Permalink
test: add vector benchmark functions
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Dec 11, 2024
1 parent 7326377 commit 5213d5c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions benchmarking/bench_vector.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 5213d5c

Please sign in to comment.