{"id":10570,"library":"benny","title":"Benny Benchmarking Framework","description":"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.","status":"active","version":"3.7.1","language":"javascript","source_language":"en","source_url":"https://github.com/caderek/benny","tags":["javascript","benchmark","benchmarking","simple","framework","async","asynchronous","async setup","await"],"install":[{"cmd":"npm install benny","lang":"bash","label":"npm"},{"cmd":"yarn add benny","lang":"bash","label":"yarn"},{"cmd":"pnpm add benny","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Benny exports a default object (`b`) containing its methods. Direct named imports for `suite`, `add`, etc., are incorrect as of v3.","wrong":"import { suite, add, cycle } from 'benny'","symbol":"b","correct":"import b from 'benny'"},{"note":"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.","wrong":"const { suite, add, cycle } = require('benny')","symbol":"b","correct":"const b = require('benny')"},{"note":"Methods like `suite`, `add`, `cycle`, `complete`, and `save` are properties of the default exported object `b` and must be accessed via `b.methodName`.","wrong":"suite('My Suite', /* ... */)","symbol":"suite","correct":"b.suite('My Suite', /* ... */)"}],"quickstart":{"code":"/* benchmark.js */\nconst b = require('benny')\n\nb.suite(\n  'Example Reduction',\n\n  b.add('Reduce two elements', () => {\n    ;[1, 2].reduce((a, b) => a + b)\n  }),\n\n  b.add('Reduce five elements', () => {\n    ;[1, 2, 3, 4, 5].reduce((a, b) => a + b)\n  }),\n\n  b.cycle(),\n  b.complete(),\n  b.save({ file: 'reduce', version: '1.0.0' }),\n  b.save({ file: 'reduce', format: 'chart.html' }),\n)","lang":"javascript","description":"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."},"warnings":[{"fix":"Run benchmarks on dedicated machines or in controlled CI/CD environments. Consider running multiple times to observe consistency.","message":"Benchmarking 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always include `b.cycle()` and `b.complete()` after your `b.add()` calls within the `b.suite()` definition.","message":"Forgetting 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your Node.js environment is version 12 or newer, as specified in the package's engine requirements.","message":"While 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.","severity":"breaking","affected_versions":"<12"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The 'b' object was not correctly imported or required, or an attempt was made to destructure methods directly from the 'benny' package.","error":"TypeError: b.suite is not a function"},{"fix":"Install the package using `npm install benny --save-dev` or `yarn add benny --dev`.","cause":"The 'benny' package has not been installed in the project.","error":"Error: Cannot find module 'benny'"},{"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.","cause":"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.","error":"Benchmark results show very low operations per second (ops/s) or high error margins."}],"ecosystem":"npm"}