From 72919423bebc7a639224ce8f4d55be7623fb0c14 Mon Sep 17 00:00:00 2001 From: francesco Date: Thu, 9 Oct 2025 12:29:20 +0200 Subject: [PATCH 1/3] feat: new benchmar with tinybench Signed-off-by: francesco --- benchmark/bench-thread.js | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/benchmark/bench-thread.js b/benchmark/bench-thread.js index 7e3ba73e..547c8d88 100644 --- a/benchmark/bench-thread.js +++ b/benchmark/bench-thread.js @@ -2,20 +2,33 @@ const { workerData: benchmark, parentPort } = require('worker_threads') -const Benchmark = require('benchmark') -Benchmark.options.minSamples = 100 +const { Bench } = require('tinybench') -const suite = Benchmark.Suite() +const bench = new Bench({ + name: benchmark.name, + time: 100, + setup: (_task, mode) => { + // Run the garbage collector before warmup at each cycle + if (mode === 'warmup' && typeof globalThis.gc === 'function') { + globalThis.gc() + } + } +}) const FJS = require('..') const stringify = FJS(benchmark.schema) -suite - .add(benchmark.name, () => { - stringify(benchmark.input) - }) - .on('cycle', (event) => { - parentPort.postMessage(String(event.target)) - }) - .on('complete', () => {}) - .run() +bench.add(benchmark.name, () => { + stringify(benchmark.input) +}).run().then(() => { + const task = bench.tasks[0] + const hz = task.result.hz // ops/sec + const rme = task.result.rme // relative margin of error (%) + const samples = task.result.samples.length + + const formattedHz = hz.toLocaleString('en-US', { maximumFractionDigits: 0 }) + const formattedRme = rme.toFixed(2) + + const output = `${task.name} x ${formattedHz} ops/sec ±${formattedRme}% (${samples} runs sampled)` + parentPort.postMessage(output) +}).catch(err => parentPort.postMessage(`Error: ${err.message}`)) From d523952d90e3a08d7e42518aa5fa440a49e3de3f Mon Sep 17 00:00:00 2001 From: francesco Date: Thu, 9 Oct 2025 10:34:59 +0000 Subject: [PATCH 2/3] feat: add tinybench --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e0655bd..516cc65b 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ ], "devDependencies": { "@sinclair/typebox": "^0.34.3", - "benchmark": "^2.1.4", "c8": "^10.1.2", "cli-select": "^1.1.2", "compile-json-stringify": "^0.1.2", @@ -73,6 +72,7 @@ "json-accelerator": "^0.0.2", "neostandard": "^0.12.0", "simple-git": "^3.23.0", + "tinybench": "^5.0.1", "tsd": "^0.32.0", "webpack": "^5.90.3" }, From 8e3ec95ce7f9ec132e209da0f92a5f627b88432b Mon Sep 17 00:00:00 2001 From: francesco Date: Thu, 9 Oct 2025 13:59:43 +0200 Subject: [PATCH 3/3] feat: add --expose-gc --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 516cc65b..8014bd71 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "bench": "node ./benchmark/bench.js", + "bench": "node --expose-gc ./benchmark/bench.js", "bench:cmp": "node ./benchmark/bench-cmp-branch.js", "bench:cmp:ci": "node ./benchmark/bench-cmp-branch.js --ci", "benchmark": "node ./benchmark/bench-cmp-lib.js",