Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test123cro
(version: 0)
test
Comparing performance of:
reduce vs foreach
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
// Create an array of 1000 random intergers between 1 and 10000 var arrRandom = []; for(var intCtr=0; intCtr<1000; intCtr++) { arrRandom.push(Math.floor(Math.random() * Math.floor(10000))); } function reduceCallback(accum, curr) { accum.push(curr); return accum; } function doRedeuce(pArray) { return pArray.reduce((arr, item) => { arr.push(item); return arr; }, []); } function doLoop(pArray) { var accum = []; for(var intCtr=0; intCtr<pArray.length; intCtr++) { accum.push(pArray[intCtr]); } return accum; } function doForEach(pArray) { var accum = []; pArray.forEach(function(item) { accum.push(item) }); }
Tests:
reduce
var redeuceResult=[]; redeuceResult = doRedeuce(arrRandom);
foreach
var forEachResult=[]; forEachResult = doForEach(arrRandom)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
reduce
foreach
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
map vs forEach vs for loop
reduce vs for loop
Array.reduce vs for loop vs Array.forEach experiments - Fix Foreach as function
Loop Testing
Array.reduce vs for loops vs Array.forEach
Comments
Confirm delete:
Do you really want to delete benchmark?