Skip to content

Commit 0920a02

Browse files
committed
feat: Support benchmark warmup with useWorkers=true
1 parent d678f9d commit 0920a02

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class Suite {
259259
}
260260

261261
// It doesn't make sense to warmup a fresh new instance of Worker.
262-
// TODO: support warmup directly in the Worker.
262+
// TODO: Should this be folded into the main loop?
263263
if (!this.#useWorkers) {
264264
// This is required to avoid variance on first benchmark run
265265
for (let i = 0; i < this.#benchmarks.length; ++i) {

lib/worker-runner.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const { parentPort } = require("node:worker_threads");
2-
const { runBenchmark } = require("./lifecycle");
2+
const {
3+
runBenchmark,
4+
getInitialIterations,
5+
runWarmup,
6+
} = require("./lifecycle");
7+
const { debugBench } = require("./clock");
38
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
49

510
// Deserialize the benchmark function
@@ -24,6 +29,16 @@ parentPort.on(
2429
minSamples,
2530
}) => {
2631
deserializeBenchmark(benchmark);
32+
33+
debugBench(
34+
`Warmup ${benchmark.name} with minTime=${benchmark.minTime}, maxTime=${benchmark.maxTime}`,
35+
);
36+
const initialIteration = await getInitialIterations(benchmark);
37+
await runWarmup(benchmark, initialIteration, {
38+
minTime: 0.005,
39+
maxTime: 0.05,
40+
});
41+
2742
const result = await runBenchmark(
2843
benchmark,
2944
initialIterations,

0 commit comments

Comments
 (0)