@@ -11,7 +11,8 @@ added: REPLACEME
1111<!-- source_link=lib/bench.js -->
1212
1313The ` node:bench ` module supports defining and running JavaScript benchmarks in
14- the current process. To access it:
14+ the current process, and running one benchmark file in a fresh child process.
15+ To access it:
1516
1617``` mjs
1718import { bench , suite } from ' node:bench' ;
@@ -497,6 +498,51 @@ for await (const { type, data } of run()) {
497498}
498499```
499500
501+ ## ` runFile(path[, options]) `
502+
503+ <!-- YAML
504+ added: REPLACEME
505+ -->
506+
507+ * ` path ` {string} The absolute path of one benchmark module.
508+ * ` options ` {Object}
509+ * ` env ` {Object} The child process environment. Property values must be
510+ strings or ` undefined ` . This replaces, rather than extends, the parent
511+ environment. ** Default:** A snapshot of ` process.env ` .
512+ * ` execArgv ` {string\[ ] } Node.js command-line options for the child process.
513+ This replaces, rather than extends, inherited options. Benchmark runner
514+ options, positional arguments, and options that select another execution
515+ mode are not allowed. ** Default:** Compatible options inherited from the
516+ current process.
517+ * ` signal ` {AbortSignal} Terminates the child process when aborted.
518+ * Returns: {BenchmarksStream}
519+
520+ Runs exactly one benchmark module in a fresh child process and returns its
521+ object-mode event stream. ` path ` is not interpreted as a glob. Unless the signal
522+ is aborted or the stream is destroyed before startup, every call uses a new
523+ child. Input discovery, ordering, concurrency, retries, and multi-file
524+ scheduling remain the caller's responsibility.
525+
526+ Records use advanced child process serialization, preserving supported
527+ structured values such as ` bigint ` and errors. Child writes to stdout and stderr
528+ become ` 'bench:diagnostic' ` records. A module loading error, abnormal child exit,
529+ or cancellation also emits an error diagnostic and produces a terminal
530+ ` 'bench:summary' ` whose ` success ` property is ` false ` ; these execution failures
531+ do not error the stream. If module evaluation fails after declaring benchmarks,
532+ those declarations still run before the unsuccessful summary.
533+
534+ ` env ` , effective inherited options, and an explicitly provided ` execArgv ` are
535+ copied when ` runFile() ` is called. The runner removes ` NODE_OPTIONS ` , replaces
536+ IPC-related environment variables, and sets its private child-context, run
537+ identity, and file identity variables, overriding properties with those names
538+ in ` env ` . Pass child Node.js options through ` execArgv ` , not ` NODE_OPTIONS ` .
539+ Standard ` child_process ` environment propagation still applies, including
540+ ` NODE_V8_COVERAGE ` , permission-model options, and required z/OS variables.
541+ Aborting ` signal ` before the child starts produces an ` AbortError ` diagnostic
542+ without spawning it. Aborting during execution sends ` SIGTERM ` to the child and
543+ escalates to ` SIGKILL ` if it does not exit. Destroying the returned stream
544+ follows the same termination procedure.
545+
500546## Class: ` BenchContext `
501547
502548An instance of ` BenchContext ` is passed to every benchmark invocation. A new
0 commit comments