For of VS for VS forEach
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
Test name
Executions per second
for of
70.6 Ops/sec
for
77.3 Ops/sec
forEach
102.1 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
array = []; for (let i = 0; i < 1000; i++) { array[i] = i; }
Tests:
for of
for(item of array) { console.log(item) }
for
for(let i = 0; i < array.length; i++){ console.log(array[i]); }
forEach
array.forEach((item) => console.log(item));
Open this result on MeasureThat.net