DEV Community

Discussion on: How to efficiently sort a large array

Collapse
 
chrisherlein profile image
Christian Herlein

Nice post, congrats!

Anyways, despite mergesort is a good algorithm, js's v8 engine implements timesort, wich is an improvement on mergesort. That results on Array#sort faster than a dev side algorithm.

Try its performance with large (or growing) inputs and compare it against -for example- inputs.sort((n1, n2) => ((n1 - n2) / Math.abs((n1 - n2))) | 0 )

That said... it's a really good explanation on sorting.

Cheers!

Collapse
 
curchadw profile image
Curtis Laurence Chadwell

I will have to look into this! Thank you by the way for the support!

Collapse
 
birowo profile image
birowo

you mean timsort : v8.dev/blog/array-sort#timsort