Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Added benchmark test GitHub Action #2366

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/benchmark-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Benchmark Tests

on:
workflow_dispatch:
schedule:
- cron: '0 10 * * 1'

env:
# Enable versioned runner quiet mode to make CI output easier to read:
OUTPUT_MODE: quiet

jobs:
benchmarks:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Run Benchmark Tests
run: node ./bin/run-bench.js --filename=${{ github.base_ref || 'main' }}_${{ matrix.node-version }}
- name: Verify Benchmark Output
mrickard marked this conversation as resolved.
Show resolved Hide resolved
run: ls benchmark_results
- name: Archive Benchmark Test
uses: actions/upload-artifact@v4
with:
name: benchmark-tests-${{ github.base_ref || 'main' }}-${{ matrix.node-version }}
path: ./benchmark_results

9 changes: 7 additions & 2 deletions bin/run-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const globs = []
const opts = Object.create(null)

process.argv.slice(2).forEach(function forEachFileArg(file) {
if (/^--/.test(file)) {
if (/^--/.test(file) && file.indexOf('=') > -1) {
// this one has a value assigned
const arg = file.substring(2).split('=')
opts[arg[0]] = arg[1]
} else if (/^--/.test(file)) {
opts[file.substring(2)] = true
} else if (/[*]/.test(file)) {
globs.push(path.join(benchpath, file))
Expand Down Expand Up @@ -69,13 +73,14 @@ class Printer {
/* eslint-enable no-console */
}
const resultPath = 'benchmark_results'
const filePrefix = opts.filename ? `${opts.filename}` : 'benchmark'
try {
await fs.stat(resultPath)
} catch (e) {
await fs.mkdir(resultPath)
}
const content = JSON.stringify(this._tests, null, 2)
const fileName = `${resultPath}/benchmark_${new Date().getTime()}.json`
const fileName = `${resultPath}/${filePrefix}_${new Date().getTime()}.json`
await fs.writeFile(fileName, content)
console.log(`Done! Test output written to ${fileName}`)
}
Expand Down