howlongdidittake
v0.1.0
Published
Measure elapsed time. Format with s, ms or ns. Both CLI and API. Small bundling size.
Downloads
3
Readme
HowLongDidItTake
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).
CLI
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.
API
Import
import * as hldit from "howlongdidittake";
Stopwatch
const getElapsedTime = hldit.stopwatch.autoUnit(2); // give precision
console.log(getElapsedTime());
const getElapsedTime = hldit.stopwatch.withUnit("ms", 2); // give unit and fraction digits
console.log(getElapsedTime());
Measure
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 ant fraction digits
measure(anyAsyncCallback).then((elapsedTime) => console.log(elapsedTime));
hldit.measure
has functions for sync callbacks as well.