Skip to content

Commit 90c4a91

Browse files
committed
use github-action-benchmark
1 parent 75b064a commit 90c4a91

1 file changed

Lines changed: 22 additions & 36 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
name: Benchmark
2-
on: [ pull_request, push, workflow_dispatch ]
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
39

410
permissions:
511
contents: read
@@ -29,41 +35,21 @@ jobs:
2935
RUST_BACKTRACE: 1
3036

3137
- name: Run Benchmarks.
32-
run: uv run pytest . --benchmark-enable --benchmark-json=output.json
38+
run: uv run pytest . -m benchmark_main --benchmark-enable --benchmark-json=output.json
3339

34-
- name: Upload benchmark artifact
35-
uses: actions/upload-artifact@v4
40+
- name: Download previous benchmark data.
41+
uses: actions/cache@v4
3642
with:
37-
name: benchmark-output
38-
path: output.json
39-
40-
- name: Append benchmark table to summary
41-
if: always()
42-
run: |
43-
if [ -f output.json ]; then
44-
echo '## Pytest Benchmark Results' >> "$GITHUB_STEP_SUMMARY"
45-
echo '' >> "$GITHUB_STEP_SUMMARY"
46-
jq -r '
47-
def fmt_ns(v):
48-
if v >= 1e9 then
49-
(100 * (v / 1e9) | round / 100 | tostring) + " s"
50-
elif v >= 1e6 then
51-
(100 * (v / 1e6) | round / 100 | tostring) + " ms"
52-
elif v >= 1e3 then
53-
(100 * (v / 1e3) | round / 100 | tostring) + " µs"
54-
else
55-
(100 * v | round / 100 | tostring) + " ns"
56-
end;
43+
path: ./benchmark-data
44+
key: benchmark-${{ github.base_ref || github.ref_name }}
5745

58-
.benchmarks
59-
| ("| Benchmark | Mean | Min | Max | Rounds | Iterations |", "|---|---:|---:|---:|---:|---:|") ,
60-
(.[] | "| " + .name +
61-
" | " + fmt_ns(.stats.mean * 1e9) +
62-
" | " + fmt_ns(.stats.min * 1e9) +
63-
" | " + fmt_ns(.stats.max * 1e9) +
64-
" | " + (.stats.rounds | tostring) +
65-
" | " + (.stats.iterations | tostring) + " |")
66-
' output.json >> "$GITHUB_STEP_SUMMARY"
67-
else
68-
echo 'No benchmark output.json found.' >> "$GITHUB_STEP_SUMMARY"
69-
fi
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' }}

0 commit comments

Comments
 (0)