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: harden sequential/test-performance · nodejs/node@acfb29c

File tree

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

‎test/sequential/test-performance.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-performance.js
+51-18Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ assert(performance);
1111
assert(performance.nodeTiming);
1212
assert.strictEqual(typeof performance.timeOrigin, 'number');
1313
// Use a fairly large epsilon value, since we can only guarantee that the node
14-
// process started up in 20 seconds.
15-
assert(Math.abs(performance.timeOrigin - Date.now()) < 20000);
14+
// process started up in 15 seconds.
15+
assert(Math.abs(performance.timeOrigin - Date.now()) < 15000);
1616

1717
const inited = performance.now();
18-
assert(inited < 20000);
18+
assert(inited < 15000);
1919

2020
{
2121
// Should work without throwing any errors
@@ -56,12 +56,43 @@ assert(inited < 20000);
5656
assert.strictEqual(performance.nodeTiming.name, 'node');
5757
assert.strictEqual(performance.nodeTiming.entryType, 'node');
5858

59+
let timeoutDelay = 111; // An extra of 111 ms for the first call.
60+
61+
function checkDelay(cb) {
62+
const defaultTimeout = 1;
63+
const timer = setInterval(checkDelay, defaultTimeout);
64+
const timeouts = 10;
65+
66+
const now = getTime();
67+
let resolved = 0;
68+
69+
function checkDelay() {
70+
resolved++;
71+
if (resolved === timeouts) {
72+
clearInterval(timer);
73+
timeoutDelay = getTime() - now;
74+
cb();
75+
}
76+
}
77+
}
78+
79+
function getTime() {
80+
const ts = process.hrtime();
81+
return Math.ceil((ts[0] * 1e3) + (ts[1] / 1e6));
82+
}
83+
5984
function checkNodeTiming(props) {
85+
console.log(props);
86+
6087
for (const prop of Object.keys(props)) {
6188
if (props[prop].around !== undefined) {
6289
assert.strictEqual(typeof performance.nodeTiming[prop], 'number');
6390
const delta = performance.nodeTiming[prop] - props[prop].around;
64-
assert(Math.abs(delta) < 1000);
91+
const delay = 1000 + timeoutDelay;
92+
assert(
93+
Math.abs(delta) < delay,
94+
`${prop}: ${Math.abs(delta)} >= ${delay}`
95+
);
6596
} else {
6697
assert.strictEqual(performance.nodeTiming[prop], props[prop],
6798
`mismatch for performance property ${prop}: ` +
@@ -83,20 +114,22 @@ checkNodeTiming({
83114
loopExit: -1
84115
});
85116

86-
setTimeout(() => {
87-
checkNodeTiming({
88-
name: 'node',
89-
entryType: 'node',
90-
startTime: 0,
91-
duration: { around: performance.now() },
92-
nodeStart: { around: 0 },
93-
v8Start: { around: 0 },
94-
bootstrapComplete: { around: inited },
95-
environment: { around: 0 },
96-
loopStart: { around: inited },
97-
loopExit: -1
98-
});
99-
}, 2000);
117+
checkDelay(() => {
118+
setTimeout(() => {
119+
checkNodeTiming({
120+
name: 'node',
121+
entryType: 'node',
122+
startTime: 0,
123+
duration: { around: performance.now() },
124+
nodeStart: { around: 0 },
125+
v8Start: { around: 0 },
126+
bootstrapComplete: { around: inited },
127+
environment: { around: 0 },
128+
loopStart: { around: inited },
129+
loopExit: -1
130+
});
131+
}, 1000);
132+
});
100133

101134
process.on('exit', () => {
102135
checkNodeTiming({

0 commit comments

Comments
0 (0)
You are visitor 01402775 — 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.