Benny Benchmarking Framework

3.7.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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' }),
)

view raw JSON →