Skip to content

Commit afd3ab4

Browse files
authored
ci: Added benchmark test GitHub Action (#2366)
Signed-off-by: mrickard <[email protected]>
1 parent 5271110 commit afd3ab4

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

.github/workflows/benchmark-tests.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Benchmark Tests
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 10 * * 1'
7+
8+
env:
9+
# Enable versioned runner quiet mode to make CI output easier to read:
10+
OUTPUT_MODE: quiet
11+
12+
jobs:
13+
benchmarks:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node-version: [16.x, 18.x, 20.x, 22.x]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
- name: Install Dependencies
28+
run: npm install
29+
- name: Run Benchmark Tests
30+
run: node ./bin/run-bench.js --filename=${{ github.base_ref || 'main' }}_${{ matrix.node-version }}
31+
- name: Verify Benchmark Output
32+
run: ls benchmark_results
33+
- name: Archive Benchmark Test
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: benchmark-tests-${{ github.base_ref || 'main' }}-${{ matrix.node-version }}
37+
path: ./benchmark_results
38+

bin/run-bench.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ const globs = []
2020
const opts = Object.create(null)
2121

2222
process.argv.slice(2).forEach(function forEachFileArg(file) {
23-
if (/^--/.test(file)) {
23+
if (/^--/.test(file) && file.indexOf('=') > -1) {
24+
// this one has a value assigned
25+
const arg = file.substring(2).split('=')
26+
opts[arg[0]] = arg[1]
27+
} else if (/^--/.test(file)) {
2428
opts[file.substring(2)] = true
2529
} else if (/[*]/.test(file)) {
2630
globs.push(path.join(benchpath, file))
@@ -69,13 +73,14 @@ class Printer {
6973
/* eslint-enable no-console */
7074
}
7175
const resultPath = 'benchmark_results'
76+
const filePrefix = opts.filename ? `${opts.filename}` : 'benchmark'
7277
try {
7378
await fs.stat(resultPath)
7479
} catch (e) {
7580
await fs.mkdir(resultPath)
7681
}
7782
const content = JSON.stringify(this._tests, null, 2)
78-
const fileName = `${resultPath}/benchmark_${new Date().getTime()}.json`
83+
const fileName = `${resultPath}/${filePrefix}_${new Date().getTime()}.json`
7984
await fs.writeFile(fileName, content)
8085
console.log(`Done! Test output written to ${fileName}`)
8186
}

0 commit comments

Comments
 (0)