Tinybench
lastmod 2025-12-11created 2025-12-111 edits
Lightweight JavaScript benchmarking library
About
- An ultra-lightweight benchmarking tool under 10KB, built to measure code performance precisely
- Works on top of Web APIs and supports accurate timing measurement using process.hrtime or performance.now
- Runs on various JavaScript runtime environments such as Node.js, Deno, and Bun
- Provides statistics-based analysis: supports latency and throughput calculations such as mean, standard deviation, margin of error, variance, and percentiles
- Concurrency execution mode: can run in parallel per task or per bench, with the threshold option controlling the maximum number of concurrent runs
- Extensible event-based structure: the Bench and Task classes inherit from EventTarget, and event listeners such as cycle and abort can be registered
- Automatic detection of asynchronous functions: checks whether a function is an AsyncFunction or returns a Promise, and sets async mode automatically
- Result visualization and conversion: the bench.table() method converts output to the console.table() format, and the output format can be customized with a user-defined Converter function
- When retainSamples is set, raw sample data is kept as is and can be used for custom analysis, graph visualization, exporting results, and more
- Selectable precise timestamp provider
- The default is performance.now()
- Supports runtime-specific optimized options such as hrtimeNow, bunNanoseconds, and auto
- A user-defined TimestampProvider interface can be implemented
- Execution can be aborted for the whole bench or for individual tasks
- On abort, an abort event is fired and a status flag (task.result.aborted) is set