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:
7 months ago
for
632K/s
for-const
631K/s
foreach
586K/s
for..of
119K/s
View exact numbers
Test name
Executions per second
✓
for
632,463 Ops/sec
for-const
631,112 Ops/sec
foreach
585,712 Ops/sec
for..of
118,585 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] }