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; doing actual work)
(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
let result = ""; for (var i = 0; i < array.length; i++) { result = result + array[i]; }
foreach
let result = ""; array.forEach(function(element) { result = result + element; });
some
array.some(function(element) { return element === "z"; });
for..of
let result = ""; for (var element of array) { result = result + element; }
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
5266828.0 Ops/sec
foreach
5589235.5 Ops/sec
some
43643776.0 Ops/sec
for..of
6686471.5 Ops/sec
Related benchmarks:
for vs foreach vs for..of (aprudnikov)
for vs for..of with strings
for vs foreach vs some vs for..of test 2
typed array for vs forEach vs for in vs for of
for vs foreach vs for..of vs for..of over entries minou
for w/length constant vs foreach vs some vs for..of (3)
for vs foreach vs for..in vs for..of 2142 34124 214 234 2342323
for vs foreach vs for...in vs for...of
for vs foreach vs some vs for..of (string array of alphabet)
Comments
Confirm delete:
Do you really want to delete benchmark?