Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of (let instead of var, and optimized for)
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
const array = new Array(100);
Tests:
for
for (let i = 0, length = array.length; i < length; i++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
for in
for (let i in array) { array[i]; }
for..of
for (let i of array) { array[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for
foreach
for in
for..of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0
Browser/OS:
Firefox 151 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
for in
27.8M/s
for
8.3M/s
foreach
4.9M/s
for..of
606K/s
View exact numbers
Test name
Executions per second
✓
for in
27,781,294 Ops/sec
for
8,274,394 Ops/sec
foreach
4,880,242 Ops/sec
for..of
606,258 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?