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 (small array)
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser:
Chrome 132
Operating system:
Chrome OS 14541.0.0
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
for
15428524.0 Ops/sec
foreach
14520560.0 Ops/sec
for in
3287515.5 Ops/sec
for..of
9296124.0 Ops/sec
for (cache length
16183961.0 Ops/sec
Script Preparation code:
var array = new Array(1);
Tests:
for
for (var i = 0; i < array.length; i++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
for in
for (var i in array) { array[i]; }
for..of
for (var i of array) { array[i]; }
for (cache length
const length = array.length for (var i = 0; i < length; i++) { array[i]; }