From 9b258d88a1819e54b84dee91064041e7d0dc02ba Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Wed, 18 Sep 2024 11:58:59 +0200 Subject: [PATCH] test: add benches for TheAlgorithms/audio_filters --- .github/workflows/codspeed.yml | 4 +- .gitmodules | 3 ++ pyproject.toml | 3 +- tests/benchmarks/TheAlgorithms | 1 + .../TheAlgorithms_bench/__init__.py | 0 .../audio_filters/__init__.py | 0 .../test_bench_butterworth_filter.py | 37 +++++++++++++++++++ .../audio_filters/test_bench_iir_filter.py | 13 +++++++ tests/benchmarks/__init__.py | 0 9 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 160000 tests/benchmarks/TheAlgorithms create mode 100644 tests/benchmarks/TheAlgorithms_bench/__init__.py create mode 100644 tests/benchmarks/TheAlgorithms_bench/audio_filters/__init__.py create mode 100644 tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_butterworth_filter.py create mode 100644 tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_iir_filter.py create mode 100644 tests/benchmarks/__init__.py diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index b13938d..c1b35d3 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -10,7 +10,9 @@ jobs: benchmarks: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + submodules: "recursive" - name: Set up Python 3.12 uses: actions/setup-python@v2 with: diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c7c81dd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/benchmarks/TheAlgorithms"] + path = tests/benchmarks/TheAlgorithms + url = git@github.com:TheAlgorithms/Python.git diff --git a/pyproject.toml b/pyproject.toml index f9c861f..4788669 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,8 +87,9 @@ force_grid_wrap = 0 float_to_top = true [tool.pytest.ini_options] -addopts = "--ignore=tests/benchmarks --ignore=tests/examples" +addopts = "--ignore=tests/benchmarks --ignore=tests/examples --ignore=tests/benchmarks/TheAlgorithms" filterwarnings = ["ignore::DeprecationWarning:pytest_benchmark.utils.*:"] +pythonpath = ["tests/benchmarks/TheAlgorithms"] [tool.coverage.run] branch = true diff --git a/tests/benchmarks/TheAlgorithms b/tests/benchmarks/TheAlgorithms new file mode 160000 index 0000000..77bbe58 --- /dev/null +++ b/tests/benchmarks/TheAlgorithms @@ -0,0 +1 @@ +Subproject commit 77bbe584216c0925e249e0baab77fef34561ecaa diff --git a/tests/benchmarks/TheAlgorithms_bench/__init__.py b/tests/benchmarks/TheAlgorithms_bench/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/benchmarks/TheAlgorithms_bench/audio_filters/__init__.py b/tests/benchmarks/TheAlgorithms_bench/audio_filters/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_butterworth_filter.py b/tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_butterworth_filter.py new file mode 100644 index 0000000..4c6373a --- /dev/null +++ b/tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_butterworth_filter.py @@ -0,0 +1,37 @@ +from audio_filters.butterworth_filter import ( + make_allpass, + make_bandpass, + make_highpass, + make_highshelf, + make_lowpass, + make_lowshelf, + make_peak, +) + + +def test_make_lowpass(benchmark): + benchmark(make_lowpass, 1000, 48000) + + +def test_make_highpass(benchmark): + benchmark(make_highpass, 1000, 48000) + + +def test_make_bandpass(benchmark): + benchmark(make_bandpass, 1000, 48000) + + +def test_make_allpass(benchmark): + benchmark(make_allpass, 1000, 48000) + + +def test_make_peak(benchmark): + benchmark(make_peak, 1000, 48000, 6) + + +def test_make_lowshelf(benchmark): + benchmark(make_lowshelf, 1000, 48000, 6) + + +def test_make_highshelf(benchmark): + benchmark(make_highshelf, 1000, 48000, 6) diff --git a/tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_iir_filter.py b/tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_iir_filter.py new file mode 100644 index 0000000..e71d006 --- /dev/null +++ b/tests/benchmarks/TheAlgorithms_bench/audio_filters/test_bench_iir_filter.py @@ -0,0 +1,13 @@ +from audio_filters.iir_filter import IIRFilter + + +def test_set_coefficients(benchmark): + filt = IIRFilter(2) + a_coeffs = [1.0, -1.8, 0.81] + b_coeffs = [0.9, -1.8, 0.81] + benchmark(filt.set_coefficients, a_coeffs, b_coeffs) + + +def test_process(benchmark): + filt = IIRFilter(2) + benchmark(filt.process, 0) diff --git a/tests/benchmarks/__init__.py b/tests/benchmarks/__init__.py new file mode 100644 index 0000000..e69de29