Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Math.max() vs for loop
(version: 1)
Compare speed of Math.max() vs for loop
Comparing performance of:
Math.max vs Reduce
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
var values = new Array(5000) for (let i = 0; i < values.length; ++i) { values[i] = i % 20 } const findMax = (arr) => { let max = -Number.Infinity for (let n = 0; n < arr.length; n++) { if (arr[n] > max) max = arr[n] } return max }
Tests:
Math.max
return Math.max(...values)
Reduce
return findMax(values)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Math.max
Reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Reduce
82K/s
Math.max
59K/s
View exact numbers
Test name
Executions per second
✓
Reduce
81,929 Ops/sec
Math.max
58,937 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?