Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of jul 2025
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of
Created:
9 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = new Array(1000);
Tests:
for
for (var i = 0; i < array.length; i++) { var x = array[i]; }
foreach
array.forEach((el)=> { var e = el; });
for in
for (var el in array) { var e = el; }
for..of
for (var el of array) { var e = el; }
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 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
1920499.2 Ops/sec
foreach
833871.2 Ops/sec
for in
80563456.0 Ops/sec
for..of
334643.2 Ops/sec
Related benchmarks:
for vs foreach vs some vs for..in
for vs foreach vs for..of (aprudnikov)
for vs foreach vs some vs for..of test 2
for vs foreach vs for..in vs for..of
for vs for..of vs for..in vs foreach
for vs foreach vs for..in vs for..of test
for vs array.foreach vs for..in vs for..of
for vs foreach vs for..in vs for..of 2
for vs foreach vs for...in vs for...of
Comments
Confirm delete:
Do you really want to delete benchmark?