Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs some vs for..of (string array of alphabet; doing actual work)
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
for
5415864.0 Ops/sec
foreach
5672463.0 Ops/sec
some
29697070.0 Ops/sec
for..of
5896532.5 Ops/sec
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; }