-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (149 loc) · 6.5 KB
/
bench.yml
File metadata and controls
155 lines (149 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Benchmarks
on:
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
benchmark:
name: Benchmark (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout PR
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@0f1b44df7e9cbb178d781a242338dfa5e243ad7f # nightly
- name: Detect CPU model (cache key + diagnostics)
id: cpu
run: |
if [ "$RUNNER_OS" = "Linux" ]; then
model=$(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | xargs)
else
model=$(sysctl -n machdep.cpu.brand_string 2>/dev/null || echo "unknown")
fi
echo "model=$model"
echo "hash=$(echo "$model" | shasum -a 256 | cut -c1-8)" >> "$GITHUB_OUTPUT"
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
prefix-key: "bench-${{ steps.cpu.outputs.hash }}"
- name: Allow perf_event_open (Linux)
if: runner.os == 'Linux'
run: sudo sysctl -w kernel.perf_event_paranoid=1
# ── Seqlock benchmarks (Criterion) ──
# IMPORTANT: Each Criterion bench must be converted IMMEDIATELY after running,
# before the next `rm -rf target/criterion`. The criterion-to-json.sh script
# reads from target/criterion/<group>/ and uses prefix matching on the bench name.
# If conversion runs after a later bench clears + overwrites criterion/, it will
# pick up the wrong bench's data.
- name: Clear Criterion cache before seqlock bench
run: rm -rf target/criterion
- name: Run seqlock benchmarks
run: cargo +nightly bench --bench seqlock
env:
RUSTFLAGS: "-C target-cpu=native"
- name: Convert seqlock Criterion results to JSON report
run: bash .github/scripts/criterion-to-json.sh seqlock
- name: Convert seqlock report for CI tracking
run: |
jq '[.results[] | {name: ("seqlock/" + .workload), unit: "ns/op", value: .ns_per_op}]' \
target/bench-report-seqlock.json > bench-output-seqlock.json
# ── Fixed-point benchmarks (Criterion) ──
- name: Clear Criterion cache before fixed-point bench
run: rm -rf target/criterion
- name: Run fixed-point benchmarks
run: cargo +nightly bench --bench fixed
env:
RUSTFLAGS: "-C target-cpu=native"
- name: Convert fixed-point Criterion results to JSON report
run: bash .github/scripts/criterion-to-json.sh fixed
- name: Convert fixed-point report for CI tracking
run: |
jq '[.results[] | {name: ("fixed/" + .workload), unit: "ns/op", value: .ns_per_op}]' \
target/bench-report-fixed.json > bench-output-fixed.json
# ── Market-state benchmarks (Criterion) ──
- name: Clear Criterion cache before market-state bench
run: rm -rf target/criterion
- name: Run market-state benchmarks
run: cargo +nightly bench --bench market_state
env:
RUSTFLAGS: "-C target-cpu=native"
- name: Convert market-state Criterion results to JSON report
run: bash .github/scripts/criterion-to-json.sh market_state
- name: Convert market-state report for CI tracking
run: |
jq '[.results[] | {name: ("market_state/" + .workload), unit: "ns/op", value: .ns_per_op}]' \
target/bench-report-market_state.json > bench-output-market_state.json
- name: Merge benchmark outputs
run: |
jq -s 'add' bench-output-seqlock.json bench-output-fixed.json bench-output-market_state.json > bench-output.json
- name: Restore Cargo.lock before gh-pages switch
run: git checkout -- Cargo.lock
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@a7bc2366eda11037936ea57d811a43b3418d3073 # v1.21.0
with:
name: Mantis Benchmarks (${{ matrix.os }})
tool: customSmallerIsBetter
output-file-path: bench-output.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: false
alert-threshold: "105%"
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: "@mantis-maintainers"
- name: Upload benchmark results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: benchmark-results-${{ matrix.os }}
path: |
target/bench-report-seqlock.json
target/bench-report-fixed.json
target/bench-report-market_state.json
bench-output.json
report:
name: Post benchmark report
needs: benchmark
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout PR
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false
- name: Download Linux results
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4
with:
name: benchmark-results-ubuntu-latest
path: results/linux
continue-on-error: true
- name: Download macOS results
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4
with:
name: benchmark-results-macos-latest
path: results/macos
continue-on-error: true
- name: Generate markdown report
run: |
linux_seqlock="results/linux/target/bench-report-seqlock.json"
macos_seqlock="results/macos/target/bench-report-seqlock.json"
linux_fixed="results/linux/target/bench-report-fixed.json"
macos_fixed="results/macos/target/bench-report-fixed.json"
linux_market_state="results/linux/target/bench-report-market_state.json"
macos_market_state="results/macos/target/bench-report-market_state.json"
bash .github/scripts/bench-report.sh \
"$linux_seqlock" "$macos_seqlock" \
"$linux_fixed" "$macos_fixed" \
"$linux_market_state" "$macos_market_state" > report.md
- name: Post PR comment
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1
with:
header: benchmark-report
path: report.md