Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.sort vs Math.min+Math.max vs reduce on bigger array of objects fix
(version: 0)
Comparing performance of:
Array.sort vs Math min and max vs reduce with min and max
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var v1 = {index:0}; var v2 = {index:1}; var arr = [v2, v1]
Tests:
Array.sort
var a = arr.sort((a,b) => a.index - b.index); var min = a[0]; var max = a[1];
Math min and max
var a = arr.map(o => o.index); var min = Math.min(...a); var max = Math.max(...a);
reduce with min and max
var a = arr.map(o => o.index); var max = a.reduce((a, b) => Math.max(a, b), -Infinity); var min = a.reduce((a, b) => Math.min(a, b), Infinity);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.sort
Math min and max
reduce with min and max
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.sort
18523086.0 Ops/sec
Math min and max
34962704.0 Ops/sec
reduce with min and max
18487608.0 Ops/sec
Related benchmarks:
array.sort.pop vs Math.max(...array)
Array.sort vs Math.max
sort vs reduce v2
sort vs reduce v3
Array.sort vs Math.min 1
Comments
Confirm delete:
Do you really want to delete benchmark?