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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser:
Chrome 142
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
for
1042791.3 Ops/sec
foreach
381554.7 Ops/sec
reduce
5187210.0 Ops/sec
for..of
812865.0 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;