Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of vs for cached
(version: 0)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of vs for cached
Created:
one year 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++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
for in
for (var i in array) { array[i]; }
for..of
for (var i of array) { array[i]; }
for cached
const arrayLength = array.length; for (var i = 0; i < arrayLength; i++) { array[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
for
foreach
for in
for..of
for cached
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/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
9335.3 Ops/sec
foreach
706150.5 Ops/sec
for in
769541.6 Ops/sec
for..of
15501.9 Ops/sec
for cached
18484.9 Ops/sec
Related benchmarks:
for cached vs foreach vs some vs for..of
for vs foreach for (cached length) vs for..of
for (cache length) vs foreach vs for..in vs for..of
for vs foreach vs for..in vs for..of vs for cached 2
Comments
Confirm delete:
Do you really want to delete benchmark?