Skip to content

Commit

Permalink
Improve benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Jul 13, 2023
1 parent 43b25d9 commit 4be426d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pint/testsuite/benchmarks/test_01_registry_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.mark.parametrize("args", [[(None,), tuple(), ("tiny",), ("", None)]])
def test_create_registry(benchmark, tiny_definition_file, args):
if args[0] == "tiny":
args = (tiny_definition_file, args[1])
args = (tiny_definition_file, args[1:])

@benchmark
def _():
Expand Down
2 changes: 1 addition & 1 deletion pint/testsuite/benchmarks/test_10_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_convert_from_uc(benchmark, my_setup, key):
benchmark(ureg._convert, 1.0, data[src], data[dst])


def test_parse_math_expression(benchmark):
def test_parse_math_expression(benchmark, my_setup):
ureg, _ = my_setup
benchmark(ureg.parse_expression, "3 + 5 * 2 + value", value=10)

Expand Down
7 changes: 5 additions & 2 deletions pint/testsuite/benchmarks/test_30_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
OP2_CMP = (operator.eq, operator.lt)
OP2_MATH = (operator.add, operator.sub, operator.mul, operator.truediv)

if np is not None:
if np is None:
NUMPY_OP1_MATH = NUMPY_OP2_CMP = NUMPY_OP2_MATH = ()
else:
NUMPY_OP1_MATH = (np.sqrt, np.square)
NUMPY_OP2_CMP = (np.equal, np.less)
NUMPY_OP2_MATH = (np.add, np.subtract, np.multiply, np.true_divide)

Expand Down Expand Up @@ -86,7 +89,7 @@ def test_build_by_mul(benchmark, setup, key):

@requires_numpy
@pytest.mark.parametrize("key", ALL_ARRAYS_Q)
@pytest.mark.parametrize("op", OP1 + (np.sqrt, np.square))
@pytest.mark.parametrize("op", OP1 + NUMPY_OP1_MATH)
def test_op1(benchmark, setup, key, op):
_, data = setup
benchmark(op, data[key])
Expand Down

0 comments on commit 4be426d

Please sign in to comment.