Skip to content

Commit

Permalink
feat: bench js
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 18, 2024
1 parent 27aed6f commit 75dbfb1
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 46 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,21 @@ jobs:
- name: Build Benchmark
run: cargo codspeed build -p rspack_benchmark --features codspeed

- name: Run benchmark
- name: Run Rust benchmark
uses: CodSpeedHQ/action@v3
timeout-minutes: 30
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}

- name: Run JavaScript benchmark
uses: CodSpeedHQ/action@v3
timeout-minutes: 30
with:
working-directory: "packages/bench"
run: pnpm run bench
token: ${{ secrets.CODSPEED_TOKEN }}

run_benchmark:
name: Run benchmark
runs-on: ubuntu-latest
Expand Down
22 changes: 22 additions & 0 deletions packages/bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Bench } from "tinybench";
import { withCodSpeed } from "@codspeed/tinybench-plugin";

function fibonacci(n) {
if (n < 2) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}

const bench = withCodSpeed(new Bench());

bench
.add("fibonacci10", () => {
fibonacci(10);
})
.add("fibonacci15", () => {
fibonacci(15);
});

await bench.run();
console.table(bench.table());
15 changes: 15 additions & 0 deletions packages/bench/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "bench",
"private": true,
"license": "MIT",
"type": "module",
"scripts": {
"bench": "node index.js"
},
"devDependencies": {
"@codspeed/tinybench-plugin": "^4.0.0",
"@rspack/cli": "workspace:*",
"@rspack/core": "workspace:*",
"tinybench": "^3.0.7"
}
}
Loading

0 comments on commit 75dbfb1

Please sign in to comment.