-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantity_benchmark.py
51 lines (37 loc) · 1.34 KB
/
quantity_benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from unitexpr import Quantity
from unitexpr.si_units import m, s
Q1 = Quantity(10.0, m ** 2)
Q2 = Quantity(20.0, s)
class TestAddition:
def test_add_quantity(self, benchmark):
def add():
return Q1 + Q1
benchmark.pedantic(add, iterations=700, rounds=4)
assert add().unit == m ** 2
assert add() == Quantity(20.0, m ** 2)
class TestDiv:
def test_div_quantity(self, benchmark):
def expr():
return Q1 / Q2
benchmark.pedantic(expr, iterations=700, rounds=4)
assert expr().unit == m ** 2 / s
assert expr() == Quantity(0.5, m ** 2 / s)
def test_div_unit(self, benchmark):
def expr():
return Q1 / s
benchmark.pedantic(expr, iterations=700, rounds=4)
assert expr().unit == m ** 2 / s
assert expr() == Quantity(10.0, m ** 2 / s)
class TestMul:
def test_mul_quantity(self, benchmark):
def expr():
return Q1 * Q2
benchmark.pedantic(expr, iterations=700, rounds=4)
assert expr().unit == m ** 2 * s
assert expr() == Quantity(200.0, m ** 2 * s)
def test_mul_unit(self, benchmark):
def expr():
return Q1 * s
benchmark.pedantic(expr, iterations=700, rounds=4)
assert expr().unit == m ** 2 * s
assert expr() == Quantity(10.0, m ** 2 * s)