Repolode
tinylibs

tinylibs/tinybench

A simple, tiny, dependency-free JavaScript benchmarking library that runs across multiple JavaScript runtimes.

Stars
2,385
Forks
60
Open issues
14
Last commit
4 hours ago

What is it?

Tinybench is a small library for measuring the performance of JavaScript functions. You create a Bench instance, add named tasks, and run them to collect latency and throughput statistics such as mean, median, standard deviation, margin of error, and percentiles. It is built on Web APIs and uses process.hrtime or performance.now for timing, so it works across several JavaScript runtimes.

Tasks can be synchronous or asynchronous, and async functions are detected automatically. Concurrency can be enabled per task or across tasks, and the library emits Event-compatible events such as cycle and warning. Options cover timer selection, optional timer overhead correction, sample retention, and AbortSignal-based cancellation. Results are exposed as data rather than logged, and bench.table() produces output for console.table().

The package has no dependencies and is distributed through npm.

Key features

  • 01Statistical analysis of latency and throughput, including percentiles and margin of error.
  • 02Synchronous and asynchronous task support with automatic async detection.
  • 03Concurrency modes for running task iterations or tasks in parallel.
  • 04EventTarget-compatible events for cycle and timer-saturation warnings.
  • 05Selectable timestamp providers and optional timer overhead correction.
  • 06AbortSignal support at both bench and task levels.

Use cases

  • Comparing the performance of alternative JavaScript implementations of the same function.
  • Measuring async operations such as I/O-bound code paths.
  • Embedding benchmarks in a test suite or CI job that inspects results programmatically.
  • Running micro-benchmarks across Node.js, Bun, or other JavaScript runtimes.

Quick start

  1. 1

    Install tinybench as a dev dependency with npm

    npm install -D tinybench
  2. 2

    Import Bench, add tasks, and call run() in your JavaScript or TypeScript file

Things to know

  • For work near the timer's resolution, the README recommends overriddenDuration because timer overhead can skew results.
  • Tasks are not logged by default, so you must extract and print results yourself.

Topics

FAQ

What is tinybench?
A simple, tiny, dependency-free JavaScript benchmarking library that runs across multiple JavaScript runtimes. Tinybench is a small library for measuring the performance of JavaScript functions. You create a Bench instance, add named tasks, and run them to collect latency and throughput statistics such as mean, median, standard deviation, margin of error, and percentiles. It is built on Web APIs and uses process.hrtime or performance.now for timing, so it works across several JavaScript runtimes.
Is tinybench free to use? What license does it have?
tinybench is open source under the MIT license. Check the license terms before using it in commercial products.
Is tinybench still maintained?
Actively maintained. The last commit to tinybench was on Oct 22, 2026.
What can I use tinybench for?
Comparing the performance of alternative JavaScript implementations of the same function. Measuring async operations such as I/O-bound code paths. Embedding benchmarks in a test suite or CI job that inspects results programmatically. Running micro-benchmarks across Node.js, Bun, or other JavaScript runtimes.
How do I install tinybench?
Install tinybench as a dev dependency with npm: npm install -D tinybench Import Bench, add tasks, and call run() in your JavaScript or TypeScript file
Where can I get tinybench?
The source code and installation instructions are on GitHub: https://github.com/tinylibs/tinybench

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects