diff --git a/.github/workflows/CI.yml b/.github/workflows/pytest.yml similarity index 92% rename from .github/workflows/CI.yml rename to .github/workflows/pytest.yml index f1fddc58..2340d9d5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/pytest.yml @@ -1,4 +1,4 @@ -name: CI +name: pytest on: push: @@ -30,6 +30,7 @@ jobs: pip install . pip install pytest pip install pytest-cov + pip install pytest-benchmark - name: Run tests run: pytest --cov=pyerrors -v diff --git a/.gitignore b/.gitignore index 18c31bfa..77feb98c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__ *.pyc .ipynb_* .coverage +.benchmarks .cache examples/B1k2_pcac_plateau.p examples/Untitled.* diff --git a/tests/benchmark_test.py b/tests/benchmark_test.py new file mode 100644 index 00000000..707b3791 --- /dev/null +++ b/tests/benchmark_test.py @@ -0,0 +1,55 @@ +import numpy as np +import pyerrors as pe +import pytest +import time + +np.random.seed(0) + +def test_bench_mul(benchmark): + length = 1000 + my_obs = pe.Obs([np.random.rand(length)], ['t1']) + + def mul(x, y): + return x * y + + benchmark(mul, my_obs, my_obs) + + +def test_bench_cmul(benchmark): + length = 1000 + my_obs = pe.CObs(pe.Obs([np.random.rand(length)], ['t1']), + pe.Obs([np.random.rand(length)], ['t1'])) + + def mul(x, y): + return x * y + + benchmark(mul, my_obs, my_obs) + + +def test_bench_matmul(benchmark): + dim = 4 + my_list = [] + length = 1000 + for i in range(dim ** 2): + my_list.append(pe.Obs([np.random.rand(length)], ['t1'])) + my_array = np.array(my_list).reshape((dim, dim)) + + benchmark(pe.linalg.matmul, my_array, my_array) + + +def test_bench_cmatmul(benchmark): + dim = 4 + my_list = [] + length = 1000 + for i in range(dim ** 2): + my_list.append(pe.CObs(pe.Obs([np.random.rand(length)], ['t1']), + pe.Obs([np.random.rand(length)], ['t1']))) + my_array = np.array(my_list).reshape((dim, dim)) + + benchmark(pe.linalg.matmul, my_array, my_array) + + +def test_bench_gamma_method(benchmark): + length = 1000 + my_obs = pe.Obs([np.random.rand(length)], ['t1']) + benchmark(my_obs.gamma_method) diff --git a/tests/test_correlators.py b/tests/correlators_test.py similarity index 100% rename from tests/test_correlators.py rename to tests/correlators_test.py diff --git a/tests/test_dirac.py b/tests/dirac_test.py similarity index 100% rename from tests/test_dirac.py rename to tests/dirac_test.py diff --git a/tests/test_fits.py b/tests/fits_test.py similarity index 100% rename from tests/test_fits.py rename to tests/fits_test.py diff --git a/tests/test_linalg.py b/tests/linalg_test.py similarity index 100% rename from tests/test_linalg.py rename to tests/linalg_test.py diff --git a/tests/test_pyerrors.py b/tests/pyerrors_test.py similarity index 100% rename from tests/test_pyerrors.py rename to tests/pyerrors_test.py diff --git a/tests/test_roots.py b/tests/roots_test.py similarity index 100% rename from tests/test_roots.py rename to tests/roots_test.py