max/min Array vs Float32Array

Benchmark created on


Setup

const arr = [
	...Array(1000)
].map(e=>~~(Math.random()*1000))

const fArr = Float32Array.from(arr)

const findMinMax = arr => arr.reduce((p, c) => {
    p[0] = c < p[0] ? c : p[0] ?? c;
    p[1] = c > p[1] ? c : p[1] ?? c;
    return p;
}, [undefined, undefined])

const findMinMax2 = arr => {
  let min = arr[0];
  let max = arr[0];
  let i = arr.length;
    
  while (i--) {
    min = arr[i] < min ? arr[i] : min;
    max = arr[i] > max ? arr[i] : max;
  }
  return { min, max };
}

Test runner

Ready to run.

Testing in
TestOps/sec
findMinMax Array
findMinMax(arr)
ready
findMinMax Float32Array
findMinMax(fArr)
ready
Math.min/max Array
Math.min(...arr)
Math.max(...arr)
ready
Math.min/max Float32Array
Math.min(...fArr)
Math.max(...fArr)
ready
findMinMax2 Array
findMinMax2(arr)
ready
findMinMax2 Float32Array
findMinMax2(fArr)
ready

Revisions

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