-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add vector benchmark functions
- Loading branch information
unexcellent
committed
Dec 11, 2024
1 parent
7326377
commit 5213d5c
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |