Finding Max in Array

Benchmark published by System on

Description

Compare ways to find the maximum value in an array.

Setup

const arr = Array.from({length: 10000}, () => Math.random() * 10000);

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Math.max.apply
Math.max.apply(null, arr);
ready
Math.max(...arr)
Math.max(...arr);
ready
for loop
let max = -Infinity;
for (let i = 0; i < arr.length; i++) {
  if (arr[i] > max) max = arr[i];
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

Revision 1
publishedby Systemon