Min Attribute Value From Array

Benchmark created on


Description

Fastest approach for finding the min value for an attribute of an array of objects

Setup

const MAX_BATCH_SIZE = 200
let minRequestSize
const requests = []
for (let x = 1; x <= 100000; x++) {
  requests.push({ template_size: Math.floor(Math.random() * (MAX_BATCH_SIZE)) })
}

Teardown

console.log(`minRequestSize: ${minRequestSize}`)

Test runner

Ready to run.

Testing in
TestOps/sec
reduce
minRequestSize = requests.reduce( (min, request) => { return request.template_size < min ? request.template_size : min }, MAX_BATCH_SIZE)
ready
spread and Math.min
minRequestSize = Math.min(MAX_BATCH_SIZE, ...requests.map(r => r.template_size))
ready

Revisions

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