Skip to content

Commit

Permalink
Enable codspeed performance measuring in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Apr 30, 2024
1 parent be6c7e7 commit 01e2623
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 316 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: CI
on: [push, pull_request]
on:
push:
branches:
- 'master' # or "master"
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:

lint:
Expand All @@ -22,7 +30,6 @@ jobs:
matrix:
os: [ubuntu-latest]
node-version:
- 14.x
- 16.x
- 18.x
- 20.x
Expand Down Expand Up @@ -61,3 +68,16 @@ jobs:
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true

benchmarks:
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-node@v3"
- name: Install dependencies
run: yarn install
- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
run: node perf/benchmark.js
token: ${{ secrets.CODSPEED_TOKEN }}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"test"
],
"devDependencies": {
"@codspeed/tinybench-plugin": "^3.1.0",
"@rubensworks/eslint-config": "^1.0.0",
"@types/jest": "^29.0.0",
"@types/n3": "^1.10.4",
Expand All @@ -68,6 +69,7 @@
"n3": "^1.16.3",
"pre-commit": "^1.2.2",
"streamify-array": "^1.0.1",
"tinybench": "^2.8.0",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0",
"yargs": "^17.7.1"
Expand Down
26 changes: 26 additions & 0 deletions perf/benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { withCodSpeed } from '@codspeed/tinybench-plugin';
import { Bench } from 'tinybench';
import { PerformanceTest } from './PerformanceTest';
import { makeTests } from './tests';

const bench = withCodSpeed(new Bench({
warmupIterations: 1,
iterations: 1,
}));
const dimension = 64;
const scope = 'all';

for (const test of makeTests(true)) {
if (test.name !== 'N3Store') {
bench.add(test.name, async() => {
await new PerformanceTest([ test ], dimension).run(scope);
});
}
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async function() {
await bench.run();
// eslint-disable-next-line no-console
console.table(bench.table());
})();

0 comments on commit 01e2623

Please sign in to comment.