Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pytest-benchmark #42

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def tests(session: Session) -> None:
"""Run the test suite."""
session.install(".")
session.install("pytest", "pytest-cov", "xdoctest")
session.install("pytest", "pytest-benchmark", "pytest-cov", "xdoctest")
session.install("opencv-python")
session.run("pytest")

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dev =
opencv-python
pre-commit
pytest
pytest-benchmark
pytest-cov
scipy
xdoctest
21 changes: 17 additions & 4 deletions tests/test_tools_dct2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
scipy.fft.idct(arr_input.T, norm="ortho").T, norm="ortho"
)

backends = ["JAX", "OPENCV", "SCIPY"]
# backends = ["JAX", "OPENCV", "SCIPY"]
backends = ["OPENCV", "SCIPY"]


@pytest.mark.parametrize("backend", backends)
def test_dct_backends(backend):
if backend == "JAX":
return

dct2d = DCT_BACKENDS[backend].dct2d
idct2d = DCT_BACKENDS[backend].idct2d

Expand All @@ -43,6 +41,8 @@ def test_dct_backends(backend):
def test_dct_backend_import(monkeypatch, backend):
import pybasic.tools.dct2d_tools

idct2d = DCT_BACKENDS[backend].idct2d

monkeypatch.setenv("BASIC_DCT_BACKEND", backend)
importlib.reload(pybasic.tools.dct2d_tools)

Expand All @@ -69,3 +69,16 @@ def test_unrecognized_backend(monkeypatch):
def test_backend_not_installed(monkeypatch, backend):
# TODO mimic package not installed by removing from path?
...


### BENCHMARKING ###
@pytest.mark.parametrize("backend", backends)
def test_dct_backends_benchmark_dct2d(backend, benchmark):
dct2d = DCT_BACKENDS[backend].dct2d
benchmark(dct2d, arr_input)


@pytest.mark.parametrize("backend", backends)
def test_dct_backends_benchmark_idct2d(backend, benchmark):
idct2d = DCT_BACKENDS[backend].idct2d
benchmark(idct2d, arr_input)