Math.max() vs Custom
n/a
Date tested:
2 months ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Test name
Executions per second
Math.max
133626.0 Ops/sec
other
102798.0 Ops/sec
Benchmark definition (click to collapse):
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);
other
const arr = values; let max = -Infinity; let min = Infinity; let len = arr.length; while (len--) { const val = arr[len]; max = val > max ? val : max; min = val < min ? val : min; } return { min, max };
Open this result on MeasureThat.net