Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..of vs for..of over entries vs for in 2
(version: 0)
Compare loop performance
Comparing performance of:
for vs foreach vs for..of vs for..of over entries vs for..in
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = Array.from({length: 100}); var t;
Tests:
for
for (let i = 0,n=array.length; i < n; i++) { t = array[i]; }
foreach
array.forEach(function(v, i) { t = v; });
for..of
for (var v of array) { t = v; }
for..of over entries
for (var [,v] of array.entries()) { t = v; }
for..in
for (var k in array) { t = array[k]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
for
foreach
for..of
for..of over entries
for..in
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser/OS:
Firefox 131 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
8424328.0 Ops/sec
foreach
7805745.5 Ops/sec
for..of
2149981.8 Ops/sec
for..of over entries
1562206.8 Ops/sec
for..in
485361.1 Ops/sec
Related benchmarks:
for vs foreach vs for..of vs for..of over entries
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 for..in vs for..of test
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 2
Comments
Confirm delete:
Do you really want to delete benchmark?