Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs some vs for..of (string array of alphabet)
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs some vs for..of
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
Tests:
for
for (var 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 (var 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
15621378.0 Ops/sec
foreach
4156878.8 Ops/sec
some
4038694.5 Ops/sec
for..of
3825905.8 Ops/sec
Related benchmarks:
for vs for..of with strings
for vs foreach vs some vs for..of test 2
Side effect: for i vs for of vs foreach
Side effect: for i vs for of vs foreach fix
Side effect: for i vs for of vs foreach fix (add multiply)
for vs for with var len
For comparison
for vs array.foreach vs for..in vs for..of
for vs foreach vs some vs for..of (string array of alphabet; doing actual work)
Comments
Confirm delete:
Do you really want to delete benchmark?