max/min Array vs Float32Array (v2)

Revision 2 of this benchmark created on


Setup

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

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
const fArr = Float32Array.from(arr)
findMinMax(fArr)
ready
Math.min/max Array
Math.min(...arr)
Math.max(...arr)
ready
Math.min/max Float32Array
const fArr = Float32Array.from(arr)
Math.min(...fArr)
Math.max(...fArr)
ready
findMinMax2 Array
findMinMax2(arr)
ready
findMinMax2 Float32Array
const fArr = Float32Array.from(arr)
findMinMax2(fArr)
ready

Revisions

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