Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array math.max vs for loop using object
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 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Math.max.apply
34892.9 Ops/sec
Math.max with spread
34956.4 Ops/sec
basic for loop
641387.0 Ops/sec
for loop length caching
630776.5 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.map((d)=>d.data));
Math.max with spread
max = Math.max(...arr.map((d)=>d.data));
basic for loop
for (let i = 0; i < arr.length; i++) { if (arr[i].data > max) { max = arr[i].data; } }
for loop length caching
for (let i = 0, len = arr.length; i < len; i++) { if (arr[i].data > max) { max = arr[i].data; } }