hrtime-now
Friendly API for process.hrtime
with some high level - date-pretty format utilities. Ideal to measure how long it take to run a function /fragment of code.
Install
npm install --save hrtime-now
Usage
now()
:
Basic: Using const t0 = // execute synchronous some task to measure timeconsole
Important: the number returned by now
doesn't mean anything special, i.e, is not performance.now()
!
High level: pretty times with timeFrom()
Pretty print the difference between given time (previouslytaken with now()
and current time). Example:
var t0 =
Could print : "somehing took 1m 29s"
High level: single statement with fromNow()
Suppose you have a (synchronous) statement like the following
const result =
You want to measure how long it takes:
const result =
or create a log function factory and don't worry about msgs:
const logTime = // use logTime() instead of fromNow from now on without worrying to pass any msg const result = // will log something like "Function ()=>compileSass took 1s"
time()
:
Using const t1 = // execute some task to measure timeconst t2 = console
Note: If you are not using ecma6 modules, you can }require()now()` like this:
const now = now
Working Example:
const now = require("hrtime-now").now
const t0 = now()
console.log(`the task took ${(now()-t0)/1000} milliseconds`)
API documentation
TODO
- asynchronous