Skip to content

Commit 893169e

Browse files
authored
Add pytest-benchmark GitHub Actions workflow (#82)
1 parent 53b68cd commit 893169e

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

.github/workflows/benchmark.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Benchmark
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
UV_FROZEN: true
15+
UV_PYTHON: 3.14
16+
RUST_VERSION: "1.90.0"
17+
18+
jobs:
19+
benchmark:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository.
24+
uses: actions/checkout@v4
25+
26+
- name: Install UV.
27+
uses: astral-sh/setup-uv@v6
28+
29+
- name: Install dependencies.
30+
run: uv sync --group testing
31+
32+
- name: Compile.
33+
run: uv pip install -v -e .
34+
env:
35+
RUST_BACKTRACE: 1
36+
37+
- name: Run Benchmarks.
38+
run: uv run pytest . -m benchmark_main --benchmark-enable --benchmark-json=output.json
39+
40+
- name: Download previous benchmark data.
41+
uses: actions/cache@v4
42+
with:
43+
path: ./benchmark-data
44+
key: benchmark-${{ github.base_ref || github.ref_name }}
45+
46+
- name: Benchmark results.
47+
uses: benchmark-action/github-action-benchmark@v1
48+
with:
49+
tool: 'pytest'
50+
output-file-path: output.json
51+
external-data-json-path: ./benchmark-data/output.json
52+
summary-always: true
53+
fail-on-alert: true
54+
skip-fetch-gh-pages: true
55+
save-data-file: ${{ github.event_name != 'pull_request' }}

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ all = [
6060
]
6161

6262
[tool.pytest.ini_options]
63+
markers = [
64+
'benchmark_main: marks tests as main benchmarks to run selectively'
65+
]
6366
addopts = [
6467
'--benchmark-columns', 'min,mean,stddev,outliers,rounds,iterations',
6568
'--benchmark-disable', # use --benchmark-enable

pytests/test_dag_cbor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ def test_dag_cbor_decode(benchmark, data) -> None:
101101
_dag_cbor_roundtrip(benchmark, data)
102102

103103

104+
@pytest.mark.benchmark_main
104105
@pytest.mark.parametrize('data', load_json_data_fixtures(_REAL_DATA_DIR), ids=lambda data: data[0])
105106
def test_dag_cbor_encode_real_data(benchmark, data) -> None:
106107
_dag_cbor_encode(benchmark, data)
107108

108109

110+
@pytest.mark.benchmark_main
109111
@pytest.mark.parametrize('data', load_json_data_fixtures(_REAL_DATA_DIR), ids=lambda data: data[0])
110112
def test_dag_cbor_decode_real_data(benchmark, data) -> None:
111113
_dag_cbor_roundtrip(benchmark, data)
@@ -116,6 +118,7 @@ def test_dag_cbor_decode_fixtures(benchmark, data) -> None:
116118
_dag_cbor_decode(benchmark, data)
117119

118120

121+
@pytest.mark.benchmark_main
119122
def test_dag_cbor_decode_torture_cids(benchmark) -> None:
120123
dag_cbor = open(_TORTURE_CIDS_DAG_CBOR_PATH, 'rb').read()
121124
benchmark(libipld.decode_dag_cbor, dag_cbor)

pytests/test_decode_car.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def car() -> bytes:
1414
return load_car_fixture(_DID, _REPO_CAR_PATH)
1515

1616

17+
@pytest.mark.benchmark_main
1718
def test_decode_car(benchmark, car) -> None:
1819
header, blocks = benchmark(libipld.decode_car, car)
1920

0 commit comments

Comments
 (0)