Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find max el of array
(version: 0)
Comparing performance of:
for of vs map vs reduce vs forEach
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var max = null; var arr = [1,3,45,7,546,56,564,454,3,2,4,6,6,7,2,46,88,32];
Tests:
for of
for(const el of arr){ if (max === null) { max = el; } else { max < el && (max = el); } } console.log('forred', max);
map
arr.map(el => { if (max === null) { max = el; } else { max < el && (max = el); } }) console.log('maped', max);
reduce
max = arr.reduce((acc, val) => { if (acc === null) { acc = val; } else { acc < val && (acc = val); } return acc; }, max); console.log('reduced', max);
forEach
arr.forEach(el => { if (max === null) { max = el; } else { max < el && (max = el); } }) console.log('forEached', max);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for of
map
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:
math.max.apply vs math.max(...)
Get max from an array of numbers (Math.max vs. iteration)
Get max from an array of numbers (Math.max vs. iteration) V2
Get max from an array of numbers (Math.max vs. iteration) V3
Javascript: reduce VS for with Math.max
Comments
Confirm delete:
Do you really want to delete benchmark?