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:
curl
Browser:
Other
Operating system:
Other
Device Platform:
Desktop
Date tested:
one year ago
for..of
1.0M/s
foreach
477K/s
for-const
27K/s
for
15K/s
View exact numbers
Test name
Executions per second
✓
for..of
1,000,074 Ops/sec
foreach
477,377 Ops/sec
for-const
27,088 Ops/sec
for
14,810 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] }