All files / src/lib/util timer.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2470x       70x 1048x   70x 1048x 1048x     70x         70x   70x        
const NS_TO_S = 1e9;
 
// seconds takes a tuple of [seconds, nanoseconds]
// and returns the time in seconds
const seconds: (diff: [number, number]) => number = (diff) =>
    diff[0] + diff[1] / NS_TO_S;
 
const newTimer: () => () => number = () => {
    const now = process.hrtime();
    return () => seconds(process.hrtime(now));
};
 
const timer = {
    seconds,
    new: newTimer,
};
 
export default timer;
 
module.exports = {
    seconds,
    new: newTimer,
};