Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of (updated)
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const array = new Array(100);
Tests:
for
const LENGTH = array.length; for (let i = 0; i < LENGTH; i++) { array[i] = Math.random(); }
foreach
array.forEach(function(i) { array[i] = Math.random(); });
for in
for (let i in array) { array[i] = Math.random(); }
for..of
for (let i of array) { array[i] = Math.random(); }
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:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0
Browser/OS:
Firefox 115 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
778740.6 Ops/sec
foreach
23551.7 Ops/sec
for in
35754.4 Ops/sec
for..of
24240.3 Ops/sec
Related benchmarks:
for vs foreach vs some
for vs foreach vs some
for vs foreach vs some vs for..of vs for cached
for cached vs foreach vs some vs for..of
foreach vs for vs for (length var) vs for..in vs for..of
for vs foreach vs some vs for..of
for vs foreach vs for..of vs for..of over entries random
for w/length constant vs foreach vs some vs for..of
for vs foreach vs for..in vs for..of (Fixed)
Comments
Confirm delete:
Do you really want to delete benchmark?