10LOC

#hrtime

Node.jsintermediate

performance.now() / hrtime.bigint() for accurate micro-benchmarks

import { performance } from "node:perf_hooks";

const benchmark = (fn: () => void, iterations = 100_000) => {
  const start = process.hrtime.bigint();
  for (let i = 0; i < iterations; i++) fn();

process.hrtime.bigint() gives nanosecond integer precision for micro-benchmarks; performance.now() is ms-resolution and good enough for most cases.