$ benchr -hbenchr – benchmark runnerUsage: benchr [options] <file>...Options: -h --help Show this screen -V --version Show version -d --delay=<s> Delay between test cycles, in seconds [default: 0] -M --min-time=<s> Minimum run time per test cycle, in seconds [default: 0] -m --max-time=<s> Maximum run time per test cycle, in seconds [default: 5] -g --grep=<s> Only run suites matching pattern -R --reporter=<name/file> Reporter to use, either a file path or built-in (`console` or `json`) [default: console] -r --require=<module> `require()` a module before starting (for instance, `babel-register`) -p --progress Show progress (depending on reporter) -P --pretty-print Pretty-print output (depending on reporter) -v --verbose More verbose output (depending on reporter)
Suites + benchmarks
A benchmark file declares one or more suites, each with one or more benchmarks to run.
NOTE: to determine if a function under test returns a promise, it is called once before the tests start. If this is undesirable, for instance due to side-effects, set the promises option for the benchmark or the entire suite:
To work around linter errors regarding suite and benchmark being undefined, your test files can export a function that would take suite and benchmark as its arguments, thereby making the linter happy:
All options map to the similarly-named command line options.
Implementing a reporter
A reporter is a CommonJS module that should export a function that gets passed a benchmark runner instance as argument.
This runner instance implements the EventEmitter interface, and will emit the following events:
run.start / run.complete
file.start / file.complete
suite.start / suite.complete
benchmark.start / benchmark.complete
The different parts are explained as follows:
a "run" consists of one or more files containing benchmarks
a "file" is a file that exports or contains one or more suites
a "suite" is a structure that consists of one or more benchmarks (where each benchmark is used in a comparison between the other benchmarks in the same suite)