• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const binding = internalBinding('performance');
4const {
5  milestones,
6  getTimeOrigin,
7} = binding;
8
9// TODO(joyeecheung): we may want to warn about access to
10// this during snapshot building.
11let timeOrigin = getTimeOrigin();
12
13function now() {
14  const hr = process.hrtime();
15  return (hr[0] * 1000 + hr[1] / 1e6) - timeOrigin;
16}
17
18function getMilestoneTimestamp(milestoneIdx) {
19  const ns = milestones[milestoneIdx];
20  if (ns === -1)
21    return ns;
22  return ns / 1e6 - timeOrigin;
23}
24
25function refreshTimeOrigin() {
26  timeOrigin = getTimeOrigin();
27}
28
29module.exports = {
30  now,
31  getMilestoneTimestamp,
32  refreshTimeOrigin,
33};
34