Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs for-const vs for..of
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 15; Mobile; rv:146.0) Gecko/146.0 Firefox/146.0
Browser:
Firefox Mobile 146
Operating system:
Android
Device Platform:
Mobile
Date tested:
4 months ago
Test name
Executions per second
for
632462.6 Ops/sec
foreach
585711.6 Ops/sec
for..of
118584.6 Ops/sec
for-const
631111.8 Ops/sec
Script Preparation code:
var array = new Array(1000);
Tests:
for
let res=0 for (var i = 0; i < array.length; i++) { res += array[i] }
foreach
let res=0 array.forEach(function(i) { res += i });
for..of
let res=0 for (var i of array) { res += i }
for-const
let res=0 const leng = array.length for (var i = 0; i < leng; i++) { res += array[i] }