GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix incorrect calculation in test-perf-hooks.js · nodejs/node@30451d3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/sequential
    • test-perf-hooks.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/sequential/test-perf-hooks.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-perf-hooks.js
+14-7Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,10 @@ const epsilon = 50;
2828
{
2929
const uptime1 = Date.now() - performance.timeOrigin;
3030
const uptime2 = performance.now();
31-
const uptime3 = process.uptime() * 1000;
3231
assert(Math.abs(uptime1 - uptime2) < epsilon,
3332
`Date.now() - performance.timeOrigin (${uptime1}) - ` +
3433
`performance.now() (${uptime2}) = ` +
3534
`${uptime1 - uptime2} >= +- ${epsilon}`);
36-
assert(Math.abs(uptime1 - uptime3) < epsilon,
37-
`Date.now() - performance.timeOrigin (${uptime1}) - ` +
38-
`process.uptime() * 1000 (${uptime3}) = ` +
39-
`${uptime1 - uptime3} >= +- ${epsilon}`);
4035
}
4136

4237
assert.strictEqual(performance.nodeTiming.name, 'node');
@@ -58,8 +53,8 @@ function checkNodeTiming(timing) {
5853
// performance.now() i.e. measures Node.js instance up time.
5954
assert.strictEqual(typeof timing.duration, 'number');
6055
assert(timing.duration > 0, `timing.duration ${timing.duration} <= 0`);
61-
assert(delta < 10,
62-
`now (${now}) - timing.duration (${timing.duration}) = ${delta} >= ${10}`);
56+
assert(delta < epsilon,
57+
`now (${now}) - timing.duration (${timing.duration}) = ${delta} >= ${epsilon}`);
6358

6459
// Check that the following fields do not change.
6560
assert.strictEqual(timing.startTime, initialTiming.startTime);
@@ -93,6 +88,18 @@ checkNodeTiming(initialTiming);
9388
assert(nodeStart < testStartTime,
9489
`nodeStart ${nodeStart} >= ${testStartTime}`);
9590

91+
{
92+
// Due to https://github.com/nodejs/node/pull/46588,
93+
// The difference between process.uptime() and (Date.now() - performance.timeOrigin)
94+
// is roughly performance.nodeTiming.nodeStart
95+
const uptime1 = Date.now() - performance.timeOrigin; // now - process start time
96+
const uptime3 = process.uptime() * 1000; // now - node start time
97+
assert(Math.abs(uptime1 - uptime3 - nodeStart) < epsilon,
98+
`Date.now() - performance.timeOrigin (${uptime1}) - ` +
99+
`process.uptime() * 1000 (${uptime3}) = ` +
100+
`${uptime1 - uptime3} >= +- ${epsilon}`);
101+
}
102+
96103
assert.strictEqual(typeof v8Start, 'number');
97104
assert(v8Start > 0, `v8Start ${v8Start} <= 0`);
98105
// V8 starts after the process starts.

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.