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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser:
Chrome 137
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
for..of
1.2M/s
foreach
1.1M/s
for-const
670K/s
for
512K/s
View exact numbers
Test name
Executions per second
✓
for..of
1,208,491 Ops/sec
foreach
1,068,364 Ops/sec
for-const
670,354 Ops/sec
for
511,969 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] }