Returns arbitrary time diffs in nanoseconds, falling back to performance.now or Date.now if process.hrtime is not available.
npm install --save atlas-hrtime
Date function or a wrapper library like
recording a time
To record the time in nano-seconds, just call the clock:
const clock = ;console
calculating a time diff
Let's say you need to test how long your
arraySort algorithm takes. All you need to do is call the clock before running your sort, then call it after running your sort with the previous time as the argument:
...const initialTime =const deltaTime =console
calculating multiple time diffs
Alternatively, you can record down times at certain points and then manually log the diffs:
...const t0 =const t1 =const t2 =const t3 = ;consoleconsoleconsole
calling the module
Make sure you call the module before using it (e.g.
require("atlas-hrtime")()). The return value of the exported function is the clock. This was done to keep the module easily testable.
All units are in nanoseconds, plain and simple -- this keeps the module minimal. You can convert to other units manually.