Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array math.max vs for loop
compare finding the maximum value with math.max using .apply & using the spread (...) operator, vs a basic for loop with an if statement, & finally a basic foor loop using length caching
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Math.max.apply
1378112.4 Ops/sec
Math.max with spread
351425.0 Ops/sec
basic for loop
376178.2 Ops/sec
for loop length caching
523836.4 Ops/sec
Script Preparation code:
var arr = []; var max = -Infinity; for (i = 0; i < 1000; i++) { arr.push(Math.random() * i); }
Tests:
Math.max.apply
max = Math.max.apply(Math, arr);
Math.max with spread
max = Math.max(...arr);
basic for loop
for (let i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; } }
for loop length caching
for (let i = 0, len = arr.length; i < len; i++) { if (arr[i] > max) { max = arr[i]; } }