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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser:
Chrome 146
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
for..of
2.5M/s
foreach
2.0M/s
for
473K/s
for-const
468K/s
View exact numbers
Test name
Executions per second
✓
for..of
2,494,248 Ops/sec
foreach
2,012,512 Ops/sec
for
472,670 Ops/sec
for-const
468,480 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] }