From 4be426df2742532090eca44a34ec8c6b9eab504b Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Thu, 13 Jul 2023 20:24:06 -0300 Subject: [PATCH] Improve benchmarks --- pint/testsuite/benchmarks/test_01_registry_creation.py | 2 +- pint/testsuite/benchmarks/test_10_registry.py | 2 +- pint/testsuite/benchmarks/test_30_numpy.py | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pint/testsuite/benchmarks/test_01_registry_creation.py b/pint/testsuite/benchmarks/test_01_registry_creation.py index 0f4559327..8b459f2bd 100644 --- a/pint/testsuite/benchmarks/test_01_registry_creation.py +++ b/pint/testsuite/benchmarks/test_01_registry_creation.py @@ -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 _(): diff --git a/pint/testsuite/benchmarks/test_10_registry.py b/pint/testsuite/benchmarks/test_10_registry.py index 2b9350964..52cf110e9 100644 --- a/pint/testsuite/benchmarks/test_10_registry.py +++ b/pint/testsuite/benchmarks/test_10_registry.py @@ -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) diff --git a/pint/testsuite/benchmarks/test_30_numpy.py b/pint/testsuite/benchmarks/test_30_numpy.py index 3a73b9c10..94e9f1519 100644 --- a/pint/testsuite/benchmarks/test_30_numpy.py +++ b/pint/testsuite/benchmarks/test_30_numpy.py @@ -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) @@ -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])