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 4c882a1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: npm run build

- name: Run benchmark
run: npm run benchmark | tee output.txt
run: npm run benchmark
# Download previous benchmark result from cache (if exists)
- name: Download previous benchmark data
uses: actions/cache@v4
Expand All @@ -44,16 +44,9 @@ jobs:
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: "benchmarkjs"
# Where the output from the benchmark tool is stored
output-file-path: output.txt
# Where the previous data file is stored
tool: "customSmallerIsBetter"
output-file-path: bench_result.json
external-data-json-path: ./cache/benchmark-data.json
# GitHub API token to make a commit comment
github-token: ${{ secrets.GH_TOKEN }}
# Enable alert commit comment
comment-on-alert: true
# Enable Job Summary for PRs
summary-always: true
# Upload the updated cache file for the next job by actions/cache
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.env
.turbo
.turbo
bench_result.json
38 changes: 28 additions & 10 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 { readFileSync, writeFileSync } from "node:fs";
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,33 @@ 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(bench.table());

writeFileSync(
"bench_result.json",
JSON.stringify(
bench.tasks.flatMap((t) => [
{
name: `${t.name} - latency`,
unit: "ms",
value: t.result.latency.mean.toFixed(3),
range: t.result.latency.range,
},
// {
// 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 4c882a1

Please sign in to comment.