Skip to content

Commit d4fa701

Browse files
committed
fix(ci): use Benchmark.js instead of Vitest Bench for CI/CD
- Switch from Vitest Bench to Benchmark.js for GitHub Actions - Install and build benchmarks in CI workflow - Extract JSON results from Benchmark.js output - Add PR comments with benchmark results - Upload both JSON and text results as artifacts - Only push to gh-pages on main branch (not PRs) Fixes: - ENOENT error for bench-results.json - Vitest Bench doesn't generate JSON output automatically - Use industry-standard Benchmark.js for consistent results Benefits: - More accurate performance measurements - Consistent with README documentation - Better integration with github-action-benchmark - Automatic PR comments with results
1 parent 0721e32 commit d4fa701

1 file changed

Lines changed: 56 additions & 4 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,32 @@ jobs:
3737
- name: Build project
3838
run: npm run build
3939

40-
- name: Run benchmarks
41-
run: npm run bench
40+
- name: Install benchmark dependencies
41+
run: cd benchmarks && npm ci
42+
43+
- name: Build benchmarks
44+
run: cd benchmarks && npm run build
45+
46+
- name: Run simple benchmark
47+
run: cd benchmarks && node build/benchmarks/simple/Mapper.performance-benchmark.js > ../benchmark-simple.txt
48+
49+
- name: Run complex benchmark
50+
run: cd benchmarks && node build/benchmarks/complex/Mapper.performance-benchmark.complex.js > ../benchmark-complex.txt
51+
52+
- name: Parse benchmark results
53+
id: parse-results
54+
run: |
55+
# Extract JSON from benchmark output (last 13 lines contain the JSON array)
56+
cd benchmarks
57+
node build/benchmarks/simple/Mapper.performance-benchmark.js 2>&1 | tail -n 13 > ../bench-results.json
58+
echo "Benchmark results:"
59+
cat ../bench-results.json
4260
4361
- name: Store benchmark result
4462
uses: benchmark-action/github-action-benchmark@v1
63+
if: github.event_name != 'pull_request'
4564
with:
46-
name: Vitest Benchmark
65+
name: Benchmark.js Performance
4766
tool: 'benchmarkjs'
4867
output-file-path: bench-results.json
4968
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -60,6 +79,39 @@ jobs:
6079
uses: actions/upload-artifact@v4
6180
with:
6281
name: benchmark-results
63-
path: bench-results.json
82+
path: |
83+
bench-results.json
84+
benchmark-simple.txt
85+
benchmark-complex.txt
6486
retention-days: 30
6587

88+
- name: Comment PR with results
89+
if: github.event_name == 'pull_request'
90+
uses: actions/github-script@v7
91+
with:
92+
script: |
93+
const fs = require('fs');
94+
const simpleResults = fs.readFileSync('benchmark-simple.txt', 'utf8');
95+
const complexResults = fs.readFileSync('benchmark-complex.txt', 'utf8');
96+
97+
const body = `## 📊 Benchmark Results
98+
99+
### Simple Mapping
100+
\`\`\`
101+
${simpleResults}
102+
\`\`\`
103+
104+
### Complex Transformations
105+
\`\`\`
106+
${complexResults}
107+
\`\`\`
108+
109+
*Benchmarked with Benchmark.js on Node.js 20*`;
110+
111+
github.rest.issues.createComment({
112+
issue_number: context.issue.number,
113+
owner: context.repo.owner,
114+
repo: context.repo.repo,
115+
body: body
116+
});
117+

0 commit comments

Comments
 (0)