-
-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (131 loc) · 4.86 KB
/
Copy pathbench.yml
File metadata and controls
161 lines (131 loc) · 4.86 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
156
157
158
159
160
161
name: Benchmarks
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
pull-requests: write
env:
CARGO_TERM_COLOR: always
jobs:
# Run and compare benchmarks on push to main (compare with previous commit)
benchmark-main:
name: Benchmark (main)
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2 # Need previous commit
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install critcmp
run: cargo install critcmp
- name: Cache cargo registry and build
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-bench-
- name: Run benchmarks on current commit
run: cargo bench --bench benchmarks -- --noplot --save-baseline current
- name: Checkout previous commit
run: git checkout HEAD~1
- name: Run benchmarks on previous commit
run: cargo bench --bench benchmarks -- --noplot --save-baseline previous
- name: Compare benchmarks
run: |
echo "## Benchmark Comparison (vs previous commit)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Comparing \`${{ github.sha }}\` against previous commit" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
critcmp previous current >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results-${{ github.sha }}
path: target/criterion
retention-days: 30
# Run and compare benchmarks on PRs (compare with base branch)
benchmark-pr:
name: Benchmark (PR)
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install critcmp
run: cargo install critcmp
- name: Cache cargo registry and build
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-bench-
- name: Run benchmarks on PR branch
run: cargo bench --bench benchmarks -- --noplot --save-baseline pr
- name: Checkout base branch
run: git checkout ${{ github.base_ref }}
- name: Run benchmarks on base branch
run: cargo bench --bench benchmarks -- --noplot --save-baseline base
- name: Compare benchmarks
run: |
echo "## Benchmark Comparison (PR vs ${{ github.base_ref }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
critcmp base pr >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
const output = execSync('critcmp base pr', { encoding: 'utf-8' });
const body = `## 📊 Benchmark Comparison
<details>
<summary>Click to expand benchmark results</summary>
\`\`\`
${output}
\`\`\`
</details>
> Compared against \`${{ github.base_ref }}\` branch
`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('Benchmark Comparison')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}