Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for loop speed comparison
(version: 1)
Comparing performance of:
for vs forEach vs for of
Created:
9 days ago
by:
Guest
Jump to the latest result
Script Preparation code:
"use strict"; const arr = []; for (let i = 0; i < 10000; i++) { arr[i] = i; }
Tests:
for
"use strict"; let x = 0; for (let i = 0; i < 10000; i++) { x = arr[i] };
forEach
"use strict"; let x = 0; arr.forEach(function(i) { x = i });
for of
"use strict"; let x = 0; for (const i of arr) { x = i };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for
forEach
for of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.4 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
9063.9 Ops/sec
forEach
3011.0 Ops/sec
for of
7959.0 Ops/sec
Related benchmarks:
For loop comparison
Test for
Test for
Test for
for-vs-foreach-vs-forof
Loop Optimization
For x for in x for of x forEach
testsssssssss
JS array for test
Comments
Confirm delete:
Do you really want to delete benchmark?