Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find Max
(version: 0)
What is most performant
Comparing performance of:
Math.max vs Reduce vs For element of array vs forEach
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var values = new Array(5000); for (let i = 0; i < values.length; ++i) { values[i] = i % 20; }
Tests:
Math.max
return Math.max(...values);
Reduce
return values.reduce((prev, curr) => { if (curr > prev) return curr; return prev; }, 0);
For element of array
let biggest = values[0]; for (let value of values) { if (value > biggest) biggest = value; }; return biggest;
forEach
let biggest = values[0]; values.forEach(element => biggest>element&&(biggest=element)); return biggest;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Math.max
Reduce
For element of array
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() vs Array.reduce() 4
Math.max() vs Array.reduce() vs for element of array loop
Find Smallest Number Not In An Array With Dynamic Max Value
Math.max() vs Array.reduce() vs For-loop
Comments
Confirm delete:
Do you really want to delete benchmark?