Skip to content

Commit 1af8940

Browse files
authored
Add codspeed and first benchmark test (#766)
1 parent 87eb61c commit 1af8940

5 files changed

Lines changed: 153 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,43 @@ jobs:
8080
- name: Upload coverage to Codecov
8181
uses: codecov/codecov-action@v5
8282
with:
83-
token: ${{ secrets.CODECOV_TOKEN }}
8483
fail_ci_if_error: true
8584

8685
- name: Upload test results to Codecov
8786
if: ${{ !cancelled() }}
8887
uses: codecov/test-results-action@v1
8988
with:
90-
token: ${{ secrets.CODECOV_TOKEN }}
9189
fail_ci_if_error: true
90+
91+
benchmarks:
92+
runs-on: "ubuntu-latest"
93+
name: Run benchmarks
94+
steps:
95+
- name: ⤵️ Checkout repository
96+
uses: actions/checkout@v4
97+
98+
- name: 🏗 Install uv
99+
uses: astral-sh/setup-uv@v5
100+
101+
- name: 🏗 Setup Python
102+
uses: actions/setup-python@v5
103+
with:
104+
python-version-file: ".python-version"
105+
106+
- name: Install additional OS dependencies
107+
run: |
108+
sudo apt-get update
109+
sudo apt-get -y install \
110+
pkg-config \
111+
liblzma-dev
112+
113+
- name: 🏗 Install the project
114+
run: |
115+
uv export --dev > requirements.txt
116+
uv pip install -e . --system -r requirements.txt
117+
118+
- name: Run benchmarks
119+
uses: CodSpeedHQ/action@main
120+
with:
121+
run: pytest tests/ --codspeed
122+
token: ${{ secrets.CODSPEED_TOKEN }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ test.py
2626
/target
2727

2828
# rust so
29-
*.cpython*.so
29+
*.cpython*.so
30+
31+
.codspeed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ dev-dependencies = [
6565
"types-pillow>=10.2.0.20240822",
6666
"maturin[patchelf]>=1.7.8",
6767
"maturin-import-hook>=0.2.0",
68+
"pytest-codspeed>=3.1.2",
6869
]
6970

7071
[tool.maturin]

tests/test_rs.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
if TYPE_CHECKING:
1414
from contextlib import AbstractContextManager
1515

16+
from pytest_codspeed import BenchmarkFixture
17+
1618

1719
@pytest.mark.parametrize(
1820
("input", "expected"),
@@ -36,10 +38,16 @@
3638
],
3739
ids=["1", "2", "3", "4"],
3840
)
39-
def test_decompress_7z_base64_data(input: str, expected: bytes) -> None:
41+
def test_decompress_7z_base64_data(
42+
benchmark: BenchmarkFixture, input: str, expected: bytes
43+
) -> None:
4044
"""Test decompress_7z_base64_data function."""
41-
assert _decompress_7z_base64_data_python(input) == expected
42-
assert decompress_7z_base64_data(input) == expected
45+
# Benchmark only the production function
46+
result = benchmark(decompress_7z_base64_data, input)
47+
assert result == expected
48+
49+
# Verify that the old python function is producing the same result
50+
assert _decompress_7z_base64_data_python(input) == result
4351

4452

4553
@pytest.mark.parametrize(

uv.lock

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)