Skip to content

Commit ae27ddd

Browse files
authored
Merge pull request #498 from theturtle32/fix-benchmark-ansi-codes
Strip ANSI control codes from benchmark output in GitHub Actions summary
2 parents ac53fda + 6f092f6 commit ae27ddd

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

.github/workflows/performance.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@ jobs:
2929
id: bench
3030
run: |
3131
echo "Running performance benchmarks..."
32-
pnpm run bench 2>&1 | tee bench-output.txt
32+
pnpm exec vitest bench --run --config vitest.bench.config.mjs --outputJson bench-results.json 2>&1 | tee bench-output.txt
3333
3434
- name: Generate benchmark summary
3535
if: always()
3636
run: |
37-
echo "## 📊 Performance Benchmark Results" >> $GITHUB_STEP_SUMMARY
38-
echo "" >> $GITHUB_STEP_SUMMARY
37+
# Parse JSON and create markdown table
38+
if [ -f bench-results.json ]; then
39+
node scripts/format-benchmarks.mjs bench-results.json >> $GITHUB_STEP_SUMMARY
40+
else
41+
echo "## 📊 Performance Benchmark Results" >> $GITHUB_STEP_SUMMARY
42+
echo "" >> $GITHUB_STEP_SUMMARY
43+
echo "⚠️ No benchmark results found" >> $GITHUB_STEP_SUMMARY
44+
echo "" >> $GITHUB_STEP_SUMMARY
45+
fi
46+
47+
# Show terminal output
48+
echo "### Terminal Output" >> $GITHUB_STEP_SUMMARY
3949
echo '```' >> $GITHUB_STEP_SUMMARY
40-
cat bench-output.txt >> $GITHUB_STEP_SUMMARY
50+
sed 's/\x1b\[[0-9;]*m//g' bench-output.txt >> $GITHUB_STEP_SUMMARY
4151
echo '```' >> $GITHUB_STEP_SUMMARY
4252
4353
- name: Check for regressions (informational)

scripts/format-benchmarks.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync } from 'fs';
4+
5+
function addCommas(num) {
6+
const str = num.toString();
7+
if (str.length <= 3) return str;
8+
return addCommas(str.slice(0, -3)) + ',' + str.slice(-3);
9+
}
10+
11+
function formatNumber(num, decimals = 4) {
12+
const multiplier = Math.pow(10, decimals);
13+
return (Math.round(num * multiplier) / multiplier).toString();
14+
}
15+
16+
function formatBenchmarkResults(jsonFile) {
17+
const data = JSON.parse(readFileSync(jsonFile, 'utf8'));
18+
19+
const lines = [];
20+
lines.push('## 📊 Performance Benchmark Results');
21+
lines.push('');
22+
lines.push('| Benchmark | Hz | Min | Max | Mean | P75 | P99 | P995 | P999 |');
23+
lines.push('|-----------|-------|------|------|------|------|------|------|------|');
24+
25+
let totalBenchmarks = 0;
26+
27+
for (const file of data.files) {
28+
for (const group of file.groups) {
29+
for (const benchmark of group.benchmarks) {
30+
totalBenchmarks++;
31+
32+
const row = [
33+
benchmark.name,
34+
addCommas(Math.floor(benchmark.hz)),
35+
formatNumber(benchmark.min),
36+
formatNumber(benchmark.max),
37+
formatNumber(benchmark.mean),
38+
formatNumber(benchmark.p75),
39+
formatNumber(benchmark.p99),
40+
formatNumber(benchmark.p995),
41+
formatNumber(benchmark.p999)
42+
];
43+
44+
lines.push('| ' + row.join(' | ') + ' |');
45+
}
46+
}
47+
}
48+
49+
lines.push('');
50+
lines.push(`_Total benchmarks: ${totalBenchmarks}_`);
51+
lines.push('');
52+
53+
return lines.join('\n');
54+
}
55+
56+
// Main execution
57+
const jsonFile = process.argv[2] || 'bench-results.json';
58+
59+
try {
60+
const markdown = formatBenchmarkResults(jsonFile);
61+
console.log(markdown);
62+
} catch (error) {
63+
console.error('Error formatting benchmark results:', error.message);
64+
process.exit(1);
65+
}

0 commit comments

Comments
 (0)