Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs some vs for..of with modern var declarations
(version: 0)
Compare loop performance
Comparing performance of:
for vs foreach vs some vs for..of
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
var array = new Array(100);
Tests:
for
for (let i = 0; i < array.length; i++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
some
array.some(function(i) { array[i]; });
for..of
for (const i of array) { array[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for
foreach
some
for..of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
some
9.2M/s
foreach
8.9M/s
for..of
365K/s
for
221K/s
View exact numbers
Test name
Executions per second
✓
some
9,187,566 Ops/sec
foreach
8,915,883 Ops/sec
for..of
364,537 Ops/sec
for
221,476 Ops/sec
Related benchmarks
for vs foreach vs some vs for..of
for vs foreach vs some vs for..of vs for in
for vs foreach vs some vs for..of vs for in
Comments
Confirm delete:
Do you really want to delete benchmark?