UNPKG

@thi.ng/bench

Version:

Benchmarking & profiling utilities w/ various statistics & formatters (CSV, JSON, Markdown etc.)

24 lines (23 loc) 393 B
import { timed, timedResult } from "./timed.js"; const bench = (fn, n = 1e6, prefix = "") => { let res; return timed(() => { while (n-- > 0) { res = fn(); } return res; }, prefix); }; const benchResult = (fn, n = 1e6) => { let res; return timedResult(() => { while (n-- > 0) { res = fn(); } return res; }); }; export { bench, benchResult };