Measure elapsed time.
- Simple. Lightweight. TypeScript friendly. Small bundling size.
- Format the result. Choose
s
,ms
orns
. Even automatically. - Limit the precision or the fraction digits.
- Available on both Node.js and browsers (maybe).
Use hldit
command.
hldit (any command)
hldit (any *.js filepath)
- On CLI, the unit is determined automatically and the precision is always
2
. I.e. just likeautoUnit(2)
via the API (see below). - If a given JavaScript file has a default export of any
Promise
type,hldit
awaits until thePromise
is resolved.
import * as hldit from "howlongdidittake";
const getElapsedTime = hldit.stopwatch.autoUnit(2); // give precision
console.log(getElapsedTime());
const getElapsedTime = hldit.stopwatch.withUnit("ms", 2); // give unit & fraction digits
console.log(getElapsedTime());
const anyAsyncCallback = () => Promise.resolve();
const measure = hldit.measure.autoUnit(2); // give precision
measure(anyAsyncCallback).then((elapsedTime) => console.log(elapsedTime));
const anyAsyncCallback = () => Promise.resolve();
const measure = hldit.measure.withUnit("ms", 2); // give unit & fraction digits
measure(anyAsyncCallback).then((elapsedTime) => console.log(elapsedTime));
hldit.measure
has functions for sync callbacks as well.