node/lib/internal/perf/utils.js
Antoine du Hamel f43d4fafeb
lib: add trailing commas in internal/perf
PR-URL: https://github.com/nodejs/node/pull/46697
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-20 01:59:21 +01:00

34 lines
640 B
JavaScript

'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,
};