Tinybench: a dependency-free JavaScript benchmark runner with its own async detection and concurrency modes
🔎 A simple, tiny and lightweight benchmarking library!
At a glance
- What is it?
- Tinybench times JavaScript functions across runtimes using only Web APIs, then reports statistically analysed latency and throughput. Its behaviours that most affect results are async detection, the concurrency mode, timer-saturation warnings and the decision not to keep samples by default.
- Who is it for?
- Tinybench fits developers who want a small, dependency-free benchmark runner that behaves the same across Node.js and other JavaScript runtimes, and who are willing to read the concurrency and async rules before trusting a number. It is not a profiler and prints nothing by default, so you must collect and present the results yourself.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository received new commits within the last day.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.
Star history
- tinylibs/tinybench2,385 ★ · +1
| Repository | 2026-09-29 | 2026-11-26 |
|---|---|---|
| tinylibs/tinybench | 2.4k | 2.4k |
1 Stars in the last 58 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Timing comes from Web APIs, so one runner works across runtimes
Tinybench is described as a simple, tiny and lightweight benchmarking library. It is completely based on Web APIs, with timing from process.hrtime or performance.now depending on the environment, so you can run the same benchmark in multiple JavaScript runtimes. It lists accurate timing, statistically analysed latency and throughput values such as standard deviation, margin of error, variance and percentiles, concurrency support, events compatible with Event and EventTarget, and no dependencies.
The package declares Node.js 20 or newer in its engines field and is published as an ES module, with a single export pointing at dist/index.js. Install it as a development dependency:
$ npm install -D tinybenchThe repository also type-checks against a workerd configuration, which is a hint that non-Node runtimes are a real target and not an afterthought.
A Bench holds uniquely named tasks and prints nothing by itself
You create a Bench, add tasks with add, and await run. The example uses a name and a time budget of 100 ms and compares a task that logs against one that waits a millisecond:
import { Bench } from 'tinybench'
const bench = new Bench({ name: 'simple benchmark', time: 100 })
bench
.add('faster task', () => {
console.log('I am faster')
})
.add('slower task', async () => {
await new Promise(resolve => setTimeout(resolve, 1)) // we wait 1ms :)
console.log('I am slower')
})
await bench.run()
console.log(bench.name)
console.table(bench.table())Two rules matter. The add method returns the Bench, so calls chain. Task names must be unique within an instance, because tasks are stored by name in a Map, and a repeated name would replace the earlier task. Tinybench also logs no result by default, so you read stats from bench.tasks or another API after the run.
The Bench constructor in the example takes a name and a time value of 100. The time value sets the time budget for each task, and the concurrency rules below refer to it again: without concurrency, each task runs until both its time budget and its minimum iteration count are met. A longer budget gives more samples and a tighter margin of error, at the price of a slower suite. More usage examples live in the examples directory, and a separate FAQ file covers common questions.
Async detection calls your function once, and you can override it
Tinybench decides whether a task is asynchronous by checking whether the function is an AsyncFunction or returns a Promise, which it learns by calling the function once. That one call is a side effect to be aware of: a task that mutates state or writes output will run once more than you expect before measurement starts.
You can set the async option to true or false when adding a task to skip detection. The guidance is careful: set async to false only for a genuinely synchronous task. To measure the synchronous cost of a function that returns a Promise, record it through overriddenDuration instead, as described in the task-supplied measurements section. A task such as one that returns Promise.resolve() can be declared with async set to true so it is awaited and timed as asynchronous work.
The README shows three cases in one snippet. An async arrow function with async set to true, a plain arrow function with async set to false, and a function that returns Promise.resolve() with async set to true. The third case is the one that matters, since detection would also classify it as asynchronous, but making the choice explicit documents the intent and avoids the detection call altogether.
Concurrency has three modes, and the threshold limits iterations rather than tasks
The concurrency option has three values. With null, the default, concurrency is disabled. With the string task, each task's iterations, meaning calls of its function, run concurrently. With bench, different tasks within the bench run concurrently.
const bench = new Bench({
concurrency: 'task', // The concurrency mode to determine how tasks are run.
threshold: 10, // Maximum concurrent iterations within a task. Defaults to Infinity.
})
await bench.run()The threshold is easy to misread: it limits concurrent iterations within a task, not concurrent benchmark tasks. Turning off the iteration limit with iterations set to 0 requires a finite threshold such as 10, not the default Infinity. The same rules apply to warmupTime and warmupIterations in warmup, and Task.warmupSync always uses the sequential rules regardless of the configured mode. Concurrent runs change what a latency number means, so compare only runs that use the same mode.
Samples are discarded by default to save memory
By default Tinybench does not keep the samples for latency and throughput, which keeps memory use low. If you want raw samples for plotting, custom analysis or exporting, you turn on retention at the bench level when creating the instance:
const bench = new Bench({ retainSamples: true })You can also enable it for one task through the options argument of add, which avoids holding samples for every task in a large suite. The trade-off is plain: summary statistics are always available, but without retained samples you cannot recompute a percentile or draw a histogram after the run. Decide before the run, because the data cannot be recovered afterwards.
Events report each cycle and warn when the timer saturates
Both Task and Bench extend EventTarget, so you can attach listeners with the standard addEventListener and removeEventListener methods. A cycle event on the bench fires for each benchmark task's cycle, while the same event on a task fires only for that task. The event carries the task.
The bench also emits a warning event when timer saturation is detected in a task's measured samples, with a reason of zero-dominated, low-distinct or zero-mad. Those reasons describe samples dominated by zeros, with few distinct values, or with a zero median absolute deviation. That is the situation you see when a task runs faster than the clock can resolve. If you see warnings, the usual remedy is to make each call do more work, because the reported numbers are not trustworthy otherwise.
Table output is customisable, and the tooling is current
The table method converts results into rows for console.table, and you can pass your own converter. The default converter reports the task name and, for completed or aborted-with-statistics tasks, latency average in nanoseconds with the relative margin of error, using helpers such as formatNumber and mToNs that the package exports.
The project builds with tsdown, tests with Vitest and uses pnpm 12.16.1. Recent releases are v6.2.3 on 2026-11-01, v6.2.2 on 2026-10-10 and v6.2.1 on 2026-10-06, and the last push was on 2026-11-02. The license is MIT. The README invites proposals for further tiny libraries, in the style of tinypool or tinyspy, through an RFC repository. The repository also holds a size-limit configuration, a bunfig.toml for Bun, a clean-publish setup that publishes from a generated package directory, and documentation generated with typedoc, which suggests that bundle size and multi-runtime support are checked as part of development.
Editorial conclusion
Tinybench fits developers who want a small, dependency-free benchmark runner that behaves the same across Node.js and other JavaScript runtimes, and who are willing to read the concurrency and async rules before trusting a number. It is not a profiler and prints nothing by default, so you must collect and present the results yourself. Check that your target runtime is on Node.js 20 or newer, and set async explicitly when a task wraps a promise.
Frequently asked questions
What does "benchmark" mean?
In Tinybench a benchmark is a timed run of a function that reports latency and throughput statistics such as standard deviation, margin of error, variance and percentiles.
How do I install Tinybench?
Run npm install -D tinybench. The package requires Node.js 20 or newer and is published as an ES module.
Does Tinybench print results automatically?
No. It logs nothing by default. You read the stats from bench.tasks after the run, or call bench.table() and pass the result to console.table.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/tinylibs-tinybench)Star history chart for your README
[](https://hysenlabs.com/projects/tinylibs-tinybench)Was this useful?