Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array for loop compare
(version: 6)
Comparing performance of:
for loop vs forEach vs for of
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const arr = new Array(10000);
Tests:
for loop
for (let i = 0; i < arr.length; i++) { console.log(arr[i]); }
forEach
arr.forEach((value, index) => { console.log(value, index); });
for of
for (const value of arr) { console.log(value); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for loop
forEach
for of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for loop
33.7 Ops/sec
forEach
130828.7 Ops/sec
for of
33.4 Ops/sec
Related benchmarks:
for.. of vs forEach
for..of vs for vs forEach
Array loop vs foreach vs while
array foreach vs loop
iterator speed1
Traditional vs For Each Loop
Array last index
for loop vs forEach vs while
JS Iteration - Test1
Comments
Confirm delete:
Do you really want to delete benchmark?