-
Notifications
You must be signed in to change notification settings - Fork 2
208 lines (184 loc) · 6.74 KB
/
Copy pathbench.yml
File metadata and controls
208 lines (184 loc) · 6.74 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Continuous Benchmarks
on:
push:
branches: [main]
paths:
- 'src/**'
- 'js/**'
- 'benches/**'
- 'Cargo.toml'
- 'Cargo.lock'
- 'package.json'
- 'package-lock.json'
pull_request:
branches: [main]
paths:
- 'src/**'
- 'js/**'
- 'benches/**'
- 'Cargo.toml'
- 'Cargo.lock'
- 'package.json'
- 'package-lock.json'
workflow_dispatch:
jobs:
benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-bench-
- name: Install dependencies
run: npm ci
- name: Build native module
run: npm run build
continue-on-error: true
- name: Generate REAL benchmark fixtures
run: node benches/setup-fixtures.js
- name: Run benchmarks on REAL fixtures
run: npm run bench:ci
- name: Download baseline results
uses: dawidd6/action-download-artifact@v3
with:
workflow: bench.yml
branch: main
name: benchmark-baseline
path: baseline/
continue-on-error: true
- name: Compare with baseline
id: compare
if: always()
run: |
if [ -f "baseline/bench-results.json" ]; then
node scripts/compare-benchmarks.js \
--current bench-results.json \
--baseline baseline/bench-results.json \
--threshold 10 \
--output bench-comparison.json
else
echo "No baseline found, this will become the baseline"
echo "regression=false" >> $GITHUB_OUTPUT
echo "regressions=0" >> $GITHUB_OUTPUT
fi
continue-on-error: true
- name: Comment PR with results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comment = '## Benchmark Results\n\n';
try {
const markdown = fs.readFileSync('bench-comparison.md', 'utf-8');
comment += markdown;
} catch (err) {
comment += 'Benchmarks completed. See artifacts for details.\n';
}
try {
const results = JSON.parse(fs.readFileSync('bench-results.json', 'utf-8'));
comment += '\n### Current Run Summary\n\n';
comment += `- **Node version:** ${results.nodeVersion}\n`;
comment += `- **Platform:** ${results.platform}\n`;
comment += `- **Patterns tested:** ${results.summary.totalPatterns}\n`;
comment += `- **Avg glob time:** ${results.summary.avgGlobTime.toFixed(2)}ms\n`;
comment += `- **Avg fast-glob time:** ${results.summary.avgFastGlobTime.toFixed(2)}ms\n`;
if (results.summary.avgGloblinTime) {
comment += `- **Avg globlin time:** ${results.summary.avgGloblinTime.toFixed(2)}ms\n`;
comment += `- **Speedup vs glob:** ${results.summary.avgSpeedupVsGlob.toFixed(1)}x\n`;
}
} catch (err) {
console.log('Could not read benchmark results:', err.message);
}
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('## Benchmark Results')
);
if (existingComment) {
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
- name: Fail if regression detected
if: steps.compare.outputs.regression == 'true'
run: |
echo "Performance regression detected (>10%)"
cat bench-comparison.md
exit 1
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
bench-results.json
bench-comparison.json
bench-comparison.md
retention-days: 30
- name: Upload as baseline (main branch only)
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: benchmark-baseline
path: bench-results.json
retention-days: 90
- name: Convert results to benchmark format
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
node -e "
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('bench-results.json', 'utf-8'));
const benchmarks = data.patterns.map(p => ({
name: p.pattern + ' (' + p.fixture + ')',
unit: 'ms',
value: p.globlin ? p.globlin.mean : p.glob.mean,
range: (p.globlin ? p.globlin.stdDev : p.glob.stdDev).toFixed(2) + ' ms',
extra: 'Results: ' + (p.globlin ? p.globlin.resultCount : p.glob.resultCount)
}));
fs.writeFileSync('benchmark-data.json', JSON.stringify(benchmarks, null, 2));
"
- name: Store benchmark result for tracking
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: benchmark-action/github-action-benchmark@v1
with:
name: Globlin Benchmarks
tool: 'customSmallerIsBetter'
output-file-path: benchmark-data.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: '150%'
comment-on-alert: true
fail-on-alert: false
gh-pages-branch: gh-pages
benchmark-data-dir-path: dev/bench
continue-on-error: true