DEV Community

Discussion on: Common Sorting Algorithms in JavaScript

Collapse
 
functional_js profile image
Functional Javascript

Excellent work Christina.
You're an expert of sorts. ;)

I perf-tested all of them.
The quickSort throws even on quite small arrays due to the stackoverflow recursion

The fastest is the merge sort, in the 1-2 second range for an array of 1M numbers.

Collapse
 
christinamcmahon profile image
Christina

First of all, good one 😂

Second, thanks for double checking and good to know about your findings! Did you test it in codepen by chance?

Collapse
 
functional_js profile image
Functional Javascript • Edited

I perf-tested these locally.

An example usage per func...

//@perftests
const aNums = genRandNums(1, 1e4, 1e6);
timeInLoop("mergeSort", 1, () => mergeSort(aNums));

genRandNums Source Code

gist.github.com/funfunction/f7adf6...

timeInLoop Source Code

gist.github.com/funfunction/91b587...

Thread Thread
 
christinamcmahon profile image
Christina

Oh this is awesome, thanks for sharing!