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:
8 months ago
Test name
Executions per second
for
12199214.0 Ops/sec
foreach
13811698.0 Ops/sec
for in
13719504.0 Ops/sec
for..of
1969544.8 Ops/sec
while (reverse)
10542825.0 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]; }