From 0920a02c26d6f33cec7f7a73ad39b0673a7d46d6 Mon Sep 17 00:00:00 2001 From: Jason Marshall Date: Tue, 30 Dec 2025 20:18:05 -0800 Subject: [PATCH] feat: Support benchmark warmup with useWorkers=true --- lib/index.js | 2 +- lib/worker-runner.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index e3e0886..9bd1455 100644 --- a/lib/index.js +++ b/lib/index.js @@ -259,7 +259,7 @@ class Suite { } // It doesn't make sense to warmup a fresh new instance of Worker. - // TODO: support warmup directly in the Worker. + // TODO: Should this be folded into the main loop? if (!this.#useWorkers) { // This is required to avoid variance on first benchmark run for (let i = 0; i < this.#benchmarks.length; ++i) { diff --git a/lib/worker-runner.js b/lib/worker-runner.js index 3b49c10..b24f0e7 100644 --- a/lib/worker-runner.js +++ b/lib/worker-runner.js @@ -1,5 +1,10 @@ const { parentPort } = require("node:worker_threads"); -const { runBenchmark } = require("./lifecycle"); +const { + runBenchmark, + getInitialIterations, + runWarmup, +} = require("./lifecycle"); +const { debugBench } = require("./clock"); const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor; // Deserialize the benchmark function @@ -24,6 +29,16 @@ parentPort.on( minSamples, }) => { deserializeBenchmark(benchmark); + + debugBench( + `Warmup ${benchmark.name} with minTime=${benchmark.minTime}, maxTime=${benchmark.maxTime}`, + ); + const initialIteration = await getInitialIterations(benchmark); + await runWarmup(benchmark, initialIteration, { + minTime: 0.005, + maxTime: 0.05, + }); + const result = await runBenchmark( benchmark, initialIterations,