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:
3 months ago
by:
Guest
Go 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:
3 months 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
for
9K/s
for of
8K/s
forEach
3K/s
View exact numbers
Test name
Executions per second
✓
for
9,064 Ops/sec
for of
7,959 Ops/sec
forEach
3,011 Ops/sec
Related benchmarks
For x for in x for of x forEach
Comments
Confirm delete:
Do you really want to delete benchmark?