Registry / testing / benny
library3.7.1jsnpmunverified

Benny (version 3.7.1) is a straightforward benchmarking framework for JavaScript and TypeScript, designed to simplify the process of performance measurement in Node.js environments. It abstracts the complexity of the underlying `benchmark.js` library, offering a more intuitive API for defining and running benchmarks. Key features include native support for synchronous and asynchronous code, per-case setup and teardown functionalities, the ability to selectively run or skip test cases, and robust result handling with options to save output to JSON, CSV, or interactive HTML charts. It provides sensible defaults, but allows for detailed configuration when needed, and integrates well with IDEs through built-in type definitions. Benny targets Node.js version 12 and above and maintains a stable release cadence. Its primary differentiator is simplifying the API over raw `benchmark.js` while retaining its powerful measurement capabilities.

npm install benny
INSTALL
IMPORT
SIG · BENNY
B
benny
testingjavascriptv3.7.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

b
import b from 'benny'
import { suite, add, cycle } from 'benny'
Benny exports a default object (`b`) containing its methods. Direct named imports for `suite`, `add`, etc., are incorrect as of v3.
b
const b = require('benny')
const { suite, add, cycle } = require('benny')
In CommonJS, require the package directly to get the main 'b' object with all benchmarking utilities. Attempting to destructure individual methods will result in undefined values.
suite
b.suite('My Suite', /* ... */)
suite('My Suite', /* ... */)
Methods like `suite`, `add`, `cycle`, `complete`, and `save` are properties of the default exported object `b` and must be accessed via `b.methodName`.

This quickstart demonstrates defining a benchmark suite with two cases, executing them, printing results to the console, and saving the results to a JSON file and an interactive HTML chart.

/* benchmark.js */ const b = require('benny') b.suite( 'Example Reduction', b.add('Reduce two elements', () => { ;[1, 2].reduce((a, b) => a + b) }), b.add('Reduce five elements', () => { ;[1, 2, 3, 4, 5].reduce((a, b) => a + b) }), b.cycle(), b.complete(), b.save({ file: 'reduce', version: '1.0.0' }), b.save({ file: 'reduce', format: 'chart.html' }), )
benny --version
Debug
Known issues
gotchaBenchmarking results are highly sensitive to the execution environment (hardware, operating system, Node.js version, other running processes). Compare results only between identical environments and ensure isolation for accurate measurements.
fix
Run benchmarks on dedicated machines or in controlled CI/CD environments. Consider running multiple times to observe consistency.
affects: >=1.0.0
gotchaWhen benchmarking asynchronous code, ensure that `beforeEach`, `afterEach`, and the benchmark function itself correctly handle promises or callbacks. Improper handling can lead to inaccurate timings or incomplete execution. Benny is designed to handle async, but user implementation must be correct.
fix
Return promises from async setup/teardown functions and benchmark cases. Ensure all async operations complete before the measurement for a given cycle is considered done.
affects: >=1.0.0
gotchaForgetting to include `b.cycle()` and `b.complete()` in your suite definition will prevent the benchmark from running or showing output. `b.cycle()` logs progress, and `b.complete()` finalizes the suite and prints the summary.
fix
Always include `b.cycle()` and `b.complete()` after your `b.add()` calls within the `b.suite()` definition.
affects: >=1.0.0
breakingWhile not explicitly noted as a breaking change in the provided README for version 3.x, older versions of Node.js (below 12) are not supported. Using Benny with an unsupported Node.js version may lead to unexpected errors or behavior.
fix
Ensure your Node.js environment is version 12 or newer, as specified in the package's engine requirements.
affects: <12
Errors
Common errors & fixes
TypeError: b.suite is not a function
The 'b' object was not correctly imported or required, or an attempt was made to destructure methods directly from the 'benny' package.
fix
Use `const b = require('benny')` for CommonJS or `import b from 'benny'` for ESM, and then call methods like `b.suite()`, `b.add()`, etc.
Error: Cannot find module 'benny'
The 'benny' package has not been installed in the project.
fix
Install the package using `npm install benny --save-dev` or `yarn add benny --dev`.
Benchmark results show very low operations per second (ops/s) or high error margins.
The benchmarked code includes I/O operations, network requests, or other factors external to the CPU-bound logic, or the benchmark runs are too short to stabilize.
fix
Isolate the critical section of code for benchmarking. Use `b.beforeEach()` and `b.afterEach()` for setup/teardown that should not be timed. Adjust `minTime` or `minSamples` options within `b.add` or `b.configure` for longer, more stable runs if needed.
Upgrade
Version history
3.7.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
benny — npm install benny · libregistry