Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of vs reverse while (let instead of var, and optimized for)
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of vs while (reverse)
Created:
8 months ago
by:
Guest
Jump 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]; }
while (reverse)
let i = array.length while(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
while (reverse)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
12199214.0 Ops/sec
foreach
13811698.0 Ops/sec
for in
13719504.0 Ops/sec
for..of
1969544.8 Ops/sec
while (reverse)
10542825.0 Ops/sec
Related benchmarks:
for vs foreach vs some vs for..in
for vs foreach vs for..of vs for..of over entries
for vs foreach vs some vs for..of
for vs foreach vs for..of vs for..of over entries (const)
for vs foreach vs for..in vs for..of
for vs foreach vs some vs for..of vs reverse for
for vs foreach vs for..of vs for..of over entries vs for in
for vs foreach vs for..of vs for..of over entries vs for in vs for cache vs for reverse
for vs foreach vs for..in vs for..of (Fixed)
Comments
Confirm delete:
Do you really want to delete benchmark?