mitata
cross-runtime benchmarking lib
Install
bun add mitata
npm install mitata
Examples
import { run, bench, group, baseline } from 'mitata';
bench('noop', () => {});
bench('noop2', () => {});
group('group', () => {
baseline('baseline', () => {});
bench('Date.now()', () => Date.now());
bench('performance.now()', () => performance.now());
});
group({ name: 'group2', summary: false }, () => {
bench('new Array(0)', () => new Array(0));
bench('new Array(1024)', () => new Array(1024));
});
await run({
avg: true,
json: false,
colors: true,
min_max: true,
collect: false,
percentiles: false,
});
JIT bias
If you run benchmarks like this, you might notice that they get slower (only few nanoseconds) after the first few runs.
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
I call this behavior "JIT bias". In simple words, v8 and JSC JIT expect us to pass the same function, so they optimize for it, but we break that promise and get deoptimized.
License
MIT © Evan