Skip to content

Commit

Permalink
use tinybeanch instead of benchmark.js
Browse files Browse the repository at this point in the history
  • Loading branch information
timheerwagen committed Nov 26, 2024
1 parent e757710 commit a29a8ce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: "benchmarkjs"
tool: "external-data-json-path"
# Where the output from the benchmark tool is stored
output-file-path: output.txt
# Where the previous data file is stored
Expand Down
32 changes: 23 additions & 9 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
import { readFileSync } from "node:fs";
import Benchmark from "benchmark";
import { Bench } from "tinybench";

const suite = new Benchmark.Suite();
const bench = new Bench({ name: "Calendar Benchmark", time: 100 });

import {
generateIcsCalendar,
Expand All @@ -13,15 +13,29 @@ const file = readFileSync("benchmark/calendar.ics", "utf-8");

const parsed = parseIcsCalendar(file);

suite
bench
.add("parse Calendar", () => {
parseIcsCalendar(file);
})
.add("generate Calendar", () => {
generateIcsCalendar(parsed);
})
.on("cycle", (event) => {
// Output benchmark result by converting benchmark result to string
console.log(String(event.target));
})
.run();
});

await bench.run();

console.log(
JSON.stringify(
bench.tasks.flatMap((t) => [
{
name: `${t.name} - latency`,
unit: "ms",
value: t.result.latency.mean.toFixed(3),
},
{
name: `${t.name} - throughput`,
unit: "ops/s",
value: t.result?.throughput.mean.toFixed(0),
},
])
)
);
30 changes: 11 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@changesets/cli": "^2.27.8",
"@neuvernetzung/tsconfig": "^1.0.2",
"@types/node": "^22.5.5",
"benchmark": "^2.1.4",
"tinybench": "^3.0.6",
"turbo": "^2.1.2"
}
}

0 comments on commit a29a8ce

Please sign in to comment.