Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of (without broken array accesses)
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of
Created:
10 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = new Array(100);
Tests:
for
for (var i = 0; i < array.length; i++) { array[i]; }
foreach
array.forEach(function(i) { i; });
for in
for (var i in array) { array[i]; }
for..of
for (var i of 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:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
26581338.0 Ops/sec
foreach
671453.8 Ops/sec
for in
10667954.0 Ops/sec
for..of
8558130.0 Ops/sec
Related benchmarks:
for vs foreach vs some vs for..in
for vs foreach vs some vs for..of - henrique
for vs foreach vs for..in vs for..of
for vs foreach vs for..in vs for..of test
for vs foreach vs for..of vs for..in
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
for vs foreach vs for..in vs for..of (small array)
Comments
Confirm delete:
Do you really want to delete benchmark?