News for hackers. Stuff that matters.
Re:WebKit sorts JS arrays using Selection Sort by simonster on Friday July 13, 2012 @10:26AM (#4239926)
Empirically, when I tested sort algorithms, Safari makes fewer calls to the comparison function than either Firefox or Chrome, and all of the sorts are definitely O(n log n) in the average case. http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/r... seems to be the real algorithm. Since Safari's sort is stable, I'm guessing that merge sort is being used.

Chrome uses quicksort + insertion sort, as mentioned in another comment. Firefox uses merge sort + insertion sort (https://mxr.mozilla.org/mozilla-central/source/js/src/jsarra...).

As a side note, Firefox's sort implementation slows down drastically when you use a custom comparison function because it has to call from C++ back out to JS (https://bugzilla.mozilla.org/show_bug.cgi?id=715181). Chrome's sort is presumably implemented in JS for this reason.

There are no comments on this comment yet.