-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
performanceIssues and PRs related to the performance of Node.js.Issues and PRs related to the performance of Node.js.questionIssues that look for answers.Issues that look for answers.v8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
Description
- Version: 7.1.0
- Platform: Windows 7 x64
- Subsystem: v8
The first iteration in cycles runs much faster than others:
[1, 2, 3, 4].forEach(() => {
const func = () => {};
const start = Date.now();
for (let i = 0; i < 100000000; i++) func();
console.log(Date.now() - start);
});544
1297
1294
1301
It renews in another cycle with a different ratio:
[1, 2, 3, 4].forEach(() => {
const func = () => {};
const start = Date.now();
for (let i = 0; i < 100000000; i++) func();
console.log(Date.now() - start);
});
console.log('');
for (let j = 1; j <= 4; j++) {
const func = () => {};
const start = Date.now();
for (let i = 0; i < 100000000; i++) func();
console.log(Date.now() - start);
}577
1312
1314
1298
437
1501
1501
1493
It becomes more strange with while cycle added in the end (this cycle removes the difference in the previous cycle, but it almost doubles its run time besides):
[1, 2, 3, 4].forEach(() => {
const func = () => {};
const start = Date.now();
for (let i = 0; i < 100000000; i++) func();
console.log(Date.now() - start);
});
console.log('');
for (let j = 1; j <= 4; j++) {
const func = () => {};
const start = Date.now();
for (let i = 0; i < 100000000; i++) func();
console.log(Date.now() - start);
}
console.log('');
let k = 4;
while (k--){
const func = () => {};
const start = Date.now();
for (let i = 0; i < 100000000; i++) func();
console.log(Date.now() - start);
}566
1317
1333
1289
2221
2448
2448
2507
2147
2360
2332
2427
Metadata
Metadata
Assignees
Labels
performanceIssues and PRs related to the performance of Node.js.Issues and PRs related to the performance of Node.js.questionIssues that look for answers.Issues that look for answers.v8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.