-
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.
Enabling 3.12, using pytest-benchmark (#61)
- Loading branch information
1 parent
ac5afdd
commit 3b8dbe6
Showing
6 changed files
with
61 additions
and
122 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
python-version: | ||
- "3.12" | ||
- "3.11" | ||
- "3.10" | ||
- "3.9" | ||
|
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
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
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
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
from pytest_benchmark.fixture import BenchmarkFixture | ||
|
||
from measured import One, Quantity | ||
from measured.astronomical import JulianYear | ||
from measured.si import Ampere, Meter, Ohm, Second, Volt | ||
from measured.us import Ounce, Ton | ||
|
||
|
||
def test_quantity_construction(benchmark: BenchmarkFixture) -> None: | ||
def quantity_construction() -> Quantity: | ||
return Quantity(1000001, Meter) | ||
|
||
result = benchmark(quantity_construction) | ||
|
||
assert result == Quantity(1000001, Meter) | ||
|
||
|
||
def test_low_dimensional_equality(benchmark: BenchmarkFixture) -> None: | ||
a = Quantity(1000, Meter) | ||
b = Quantity(1000, Meter) | ||
|
||
def low_dimensional_equality() -> bool: | ||
return bool(a == b) | ||
|
||
assert benchmark(low_dimensional_equality) is True | ||
|
||
|
||
def test_high_dimensional_equality(benchmark: BenchmarkFixture) -> None: | ||
a = Quantity(1000, Ohm) | ||
b = Quantity(1000, Ohm) | ||
|
||
def high_dimensional_equality() -> bool: | ||
return bool(a == b) | ||
|
||
assert benchmark(high_dimensional_equality) is True | ||
|
||
|
||
def test_computing_resistances(benchmark: BenchmarkFixture) -> None: | ||
a = Quantity(1000, Ampere) | ||
v = Quantity(1000, Volt) | ||
|
||
def computing_resistances() -> Quantity: | ||
return v / a | ||
|
||
assert benchmark(computing_resistances) == Quantity(1, Ohm) | ||
|
||
|
||
def test_complicated_conversions(benchmark: BenchmarkFixture) -> None: | ||
o = Quantity(1000, Ounce / (JulianYear * Ampere)) | ||
t = Quantity(1000, Ton / (Second * Ampere)) | ||
|
||
def divide() -> Quantity: | ||
return (t / o).in_unit(One) | ||
|
||
assert benchmark(divide).unit == One |