Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
2 spread + 2 Maps + 1 Math.min() + 1 Math.max() vs 1 Array.reduce()
Compare speed of spreading and executing Math.min() and Math.max() for one array vs Array.reduce().
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
2 spreading and executing Math.min() and Math.max()
13538.6 Ops/sec
1 spreading and executing Math.min() and Math.max()
21407.6 Ops/sec
No spreading and executing .reduce one time
16164.6 Ops/sec
Script Preparation code:
var v = new Array(10000); var values = [] for (let i = 0; i < v.length; ++i) { values.push({value: i % 20}) }
Tests:
2 spreading and executing Math.min() and Math.max()
const min = Math.min(...values.map(i => i.value)); const max = Math.max(...values.map(i => i.value)); return {min, max}
1 spreading and executing Math.min() and Math.max()
const mapped = values.map(i => i.value) const min = Math.min(...mapped); const max = Math.max(...mapped); return {min, max}
No spreading and executing .reduce one time
return values.reduce( (acc, {value} ) => { if (acc.min > value) acc.min = value if (acc.max < value) acc.max = value return acc }, { min: Infinity, max: 0 } )