All files / lib/internal/perf utils.js

100% Statements 33/33
100% Branches 6/6
100% Functions 3/3
100% Lines 33/33

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 24 25 26 27 28 29 30 31 32 33 3427x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 113239x 113239x 113239x 113239x 27x 239x 239x 239x 239x 186x 239x 27x 5978x 5978x 5978x 27x 27x 27x 27x 27x 27x  
'use strict';
 
const binding = internalBinding('performance');
const {
  milestones,
  getTimeOrigin,
} = binding;
 
// TODO(joyeecheung): we may want to warn about access to
// this during snapshot building.
let timeOrigin = getTimeOrigin();
 
function now() {
  const hr = process.hrtime();
  return (hr[0] * 1000 + hr[1] / 1e6) - timeOrigin;
}
 
function getMilestoneTimestamp(milestoneIdx) {
  const ns = milestones[milestoneIdx];
  if (ns === -1)
    return ns;
  return ns / 1e6 - timeOrigin;
}
 
function refreshTimeOrigin() {
  timeOrigin = getTimeOrigin();
}
 
module.exports = {
  now,
  getMilestoneTimestamp,
  refreshTimeOrigin
};