nstdlib-nightly
Version:
Node.js standard library converted to runtime-agnostic ES modules.
34 lines (27 loc) • 922 B
JavaScript
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/perf/utils.js
import {
constants as __constants__,
milestones,
now,
} from "nstdlib/stub/binding/performance";
const {
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN,
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP,
} = __constants__;
function getTimeOrigin() {
// Do not cache this to prevent it from being serialized into the
// snapshot.
return milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN] / 1e6;
}
// Returns the milestone relative to the process start time in milliseconds.
function getMilestoneTimestamp(milestoneIdx) {
const ns = milestones[milestoneIdx];
if (ns === -1) return ns;
return ns / 1e6 - getTimeOrigin();
}
function getTimeOriginTimestamp() {
return milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP] / 1e3;
}
export { now };
export { getMilestoneTimestamp };
export { getTimeOriginTimestamp };