Development0 views

Node.js Gets Native Benchmark Runner: What node:bench Means for Performance Testing

Node.js is gaining an experimental module called node:bench that simplifies performance measurement directly within the runtime. Proposed in PRs #65606 and #65631, this addition fills a long-standing gap: while Node.js already has a native test runner (node:test), it has lacked an official benchmark runner until now.

The new module mirrors the test runner's API, using familiar functions like bench and suite. This keeps the learning curve gentle for developers already writing tests in Node.js. You can write benchmarks in .mjs files and execute them via CLI with node --bench benchmark.mjs. The command supports explicit files or glob patterns, orders execution, and lets you configure samples, warmup iterations, name-based filtering, and output formats. By default, each file runs in a separate child process, isolating module state and heap memory to prevent cross-benchmark contamination.

Beyond CLI usage, node:bench supports programmatic access. The run() function returns a BenchmarksStream that emits lifecycle records, enabling advanced tools to build custom integrations and pipelines. Additional APIs include createRunner for isolated runners, runFile for executing files in child processes, and context.diagnostic for emitting info or warning messages during benchmarks. Currently marked as Stability 1.0 (Early Development) with experimental CLI flags, the trajectory points toward standardized benchmarking becoming a core Node.js feature.