Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs for..in vs for..of vs reverse while (let instead of var, and optimized for)
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/139.0.0.0 Safari/537.36
Browser:
Chrome 139
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
foreach
13.8M/s
for in
13.7M/s
for
12.2M/s
while (reverse)
10.5M/s
for..of
2.0M/s
View exact numbers
Test name
Executions per second
✓
foreach
13,811,698 Ops/sec
for in
13,719,504 Ops/sec
for
12,199,214 Ops/sec
while (reverse)
10,542,825 Ops/sec
for..of
1,969,545 Ops/sec
Script Preparation code:
const array = new Array(100);
Tests:
for
for (let i = 0, length = array.length; i < length; i++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
for in
for (let i in array) { array[i]; }
for..of
for (let i of array) { array[i]; }
while (reverse)
let i = array.length while(i--){ array[i]; }