Script Preparation code:
x
 
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];
      }
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Math.max.apply
    Math.max with spread
    basic for loop
    for loop length caching

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 days ago)
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
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
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