run(options?): BenchmarksStream
Attributes
options:
ObjectOnly runs benchmarks whose full hierarchical
name matches the pattern. String values are interpreted as JavaScript
regular expressions.
samples:
numberOverrides the maximum number of measured callback
invocations for every benchmark. Must be a positive 32-bit unsigned integer.
signal:
AbortSignalAllows aborting in-progress benchmark execution.
warmup:
numberOverrides the number of unreported warmup callback
invocations for every benchmark. Must be a 32-bit unsigned integer.
yieldBetweenSamples?:
booleanSchedule an event loop turn between sample
callbacks. Default:
true, or the value passed to createRunner() for
an explicit runner.Returns:
BenchmarksStreamReturns the object-mode event stream for the in-process benchmark run. Call
run() during the same turn in which benchmarks are declared, before automatic
execution begins. Calling run() is optional when the returned stream is not
needed. An explicit runner created by createRunner() does not run
automatically, so its run() function may be called later.
import { bench, run } from 'node:bench'; bench('example', { samples: 3 }, (b) => { b.start(); doWork(); b.end(1); }); for await (const { type, data } of run()) { if (type === 'bench:complete' && data.error === undefined) { console.log(data.name, data.summary.mean); } }