# How fast is Math.max (v2)

## Description

Does the fact that this method accept a list of arguments instead of array affects its performance?

## Setup

``````const fill = (N) => {
const n = 0.01 * N,
nN = N - n,
MN = 1000,
kM = MN/N,
km = nN*MN/N/N;
return [...new Array(N)]
.map((_, i) => i)
.map(i => [i*kM, i*km])
.map(([M, m]) => m+Math.random(M-m));
}

const data = fill(100000);

const max2MathMax = (a, b) => Math.max(a,b);
const max2Tern = (a, b) => a > b ? a : b;

function myReduce(arr, f) {
let acc = f(arr[0], arr[1]);
for (let i = 1; i < arr.length; i++) {
acc = f(acc, arr[i]);
}
return acc;
}``````

## Test runner

Testing in
TestOps/sec
Math.max
``const max = Math.max(...data);``
reduce + ternary
``const max = data.reduce(max2Tern);``
for + ternary
``````let max = data[0];

for (let i = 1; i < data.length; i++) {
max = max2Tern(data[i], max);
}``````
reduce + Math.max
``const max = data.reduce(max2MathMax);``
for + Math.max
``````let max = data[0];

for (let i = 1; i < data.length; i++) {
max = max2MathMax(data[i], max);
}
``````
``````const max = myReduce(data, max2Tern);