Bencho is inspired by hyperfine, but it measures explicit markers emitted by the benchmarked process instead of only measuring the process runtime. This is useful when you need to benchmark a specific operation inside a larger program or compare application-level metrics.
Markers are plain text lines written to stdout or stderr. They can represent time, memory, or any numeric value. You can emit any number of markers from any language, framework, logger, or tracing tool.
Bencho starts your command, reads stdout and stderr, extracts marker lines, groups them by label and type, and reports statistics.
:book: Bencho does not transform or instrument your code.
You can print marker lines manually with console.log or console.error, or use the helper functions exported by bencho. If markers should not be present in production builds, gate or remove them in your own build process.
Installation
:book: Right now we only support installation from the npm registry.
npm install --save-dev bencho
Usage
Use bencho --help for the full CLI reference. More examples are available in the ./examples directory.
The examples below use bencho. For a local project install, run it as npx bencho or from an npm script.
Before adding markers:
// ./code.mjsasync function findAllEmptyResolutions() { /* code */ }await findAllEmptyResolutions();
After adding markers:
// ./code.mjsimport { performance } from 'node:perf_hooks';import * as bencho from 'bencho';async function findAllEmptyResolutions() { /* code */ }const startTime = performance.now();await findAllEmptyResolutions();const time = performance.now() - startTime;const memory = process.memoryUsage().heapUsed;bencho.time('time', time);bencho.memory('memory', memory);
Run a fixed number of measured runs:
$ bencho 'node ./code.mjs' --warmup 10 --runs 50
--warmup runs are executed before measurement and are not included in the result. --runs selects exact mode and performs exactly that many measured runs.
When --runs is omitted, Bencho uses adaptive mode. In this mode, the first measured run determines how many measured runs will be collected:
The calculated count includes the first measured run. By default, adaptive mode uses at least 10 measured runs and an internal 3 second target. --min-runs changes the minimum, and --max-runs caps the measured run count.
if the first measured run takes about 400ms, Bencho runs 10 warmup runs and 10 measured runs;
if it takes about 100ms, Bencho runs 10 warmup runs and 30 measured runs.
The internal 3 second target is only used to estimate the run count. It is not a timeout and does not limit total benchmark duration. Use --max-runs when fast commands would otherwise run too many times.
--runs cannot be combined with --min-runs or --max-runs.
Results:
Benchmark #1Command: node ./code.mjs node ./code.mjsMarker Type Mean StdDev StdDev, % Min Max------------ ------ --------- ------- --------- --------- ---------time time 0.011ms 0.002ms 19.064% 0.008ms 0.017msprocess.time time 36.135ms 2.163ms 5.985% 33.077ms 43.087msmemory memory 5.127 MiB 0.000 B 0.000% 5.127 MiB 5.127