Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs reduce 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/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
for
2074562.0 Ops/sec
foreach
1356610.4 Ops/sec
reduce
7048786.0 Ops/sec
for..of
1477114.8 Ops/sec
Script Preparation code:
var array = Array.from({ length: 200 }, () => { return Math.floor(Math.random() * (32000 - 0 + 1)) + 0; })
Tests:
for
let result = 0; for (var i = 0; i < array.length; i++) { result += array[i]; } result;
foreach
let result = 0; array.forEach(function(i) { result += array[i]; }); result;
reduce
let result = array.reduce((accumulator, currentValue) => { return accumulator + currentValue; }, 0); result;
for..of
let result = 0; for (var i of array) { result += array[i]; } result;