API @deepkit/bench
npm install @deepkit/bench
A simple tool to benchmark code snippets.
import { benchmark, run } from '@deepkit/bench'; // ASCII binary parsing example const binaryString = Buffer.from('Hello World', 'utf8'); const codes = [ benchmark('Buffer.toString', () => { const utf8String = binaryString.toString('utf8'); }); benchmark('String.fromCodePoint', () => { const utf8String = String.fromCodePoint() }); void run();
$ node --import @deepkit/run benchmarks/ascii-parsing.ts Node v22.13.1 🏎 x 20,326,482.53 ops/sec ± 4.95% 0.000049 ms/op ▆▆▇▅▆▆▅▅▆▅▅▅▅▅▅▅▅▅▅▅▅▅ Buffer.toString 19850001 samples 🏎 x 36,012,545.69 ops/sec ± 1.78% 0.000028 ms/op ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ String.fromCodePoint 35800001 samples done
Registers a benchmark with the given name and function.
Function can be synchronous or asynchronous. Runs all registered benchmarks each for the given number of seconds.Functions
benchmark [source] (name: string, fn: () => void): void
run [source] (seconds?: number): Promise<void>