diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 218a7f1..41a0bcc 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 563f443..41ea6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .env -.turbo \ No newline at end of file +.turbo +bench_result.json \ No newline at end of file diff --git a/benchmark/index.js b/benchmark/index.js index dfa7773..95d0f5d 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -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, @@ -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), + // }, + ]) + ) +); diff --git a/package-lock.json b/package-lock.json index 0705525..e030522 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,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" } }, @@ -3011,17 +3011,6 @@ "dev": true, "license": "MIT" }, - "node_modules/benchmark": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", - "integrity": "sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "lodash": "^4.17.4", - "platform": "^1.3.3" - } - }, "node_modules/better-path-resolve": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/better-path-resolve/-/better-path-resolve-1.0.0.tgz", @@ -6269,13 +6258,6 @@ "node": ">=8" } }, - "node_modules/platform": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", - "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", - "dev": true, - "license": "MIT" - }, "node_modules/postcss-load-config": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/postcss-load-config/-/postcss-load-config-6.0.1.tgz", @@ -7052,6 +7034,16 @@ "node": ">=0.8" } }, + "node_modules/tinybench": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-3.0.6.tgz", + "integrity": "sha512-ljQ0LM7ePiVrjM8KHkHUWH+eVo36hwpE34dqYvOJIvzVJvzqXwTpjjw/bLjduqU50Z8CuhVFgFN1U7yLaSCsCg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/tinyglobby": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.6.tgz", diff --git a/package.json b/package.json index dfa42d1..b78d8e4 100644 --- a/package.json +++ b/package.json @@ -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" } }