-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
After running small benchmark on Windows 10 with x64_debug config, i've got these results:
13996ms (for-of), 90ms (for-non-cached), 63ms (for-cached) (on average after 10 subsequent runs)
For-of is slower than for-non-cached by 15551%
and For-of is slower than for-cached by 22215%!
Bench code:
{
const a = Array.from({ length: 1e7 }, _ => 0);
let start = (console.log('Start'), Date.now());
for (const _ of a);
console.log(Date.now() - start + 'ms (for-of)');
start = Date.now();
for (let i = 0; i < a.length; i++) { const _ = a[i]; }
console.log(Date.now() - start + 'ms (for-non-cached)');
start = Date.now();
const length = a.length;
for (let i = 0; i < length; i++) { const _ = a[i]; }
console.log(Date.now() - start + 'ms (for-cached)');
}