Why Javascript implementation of Bubble sort much faster than others sorting algorithms? <p>I have done some <a href="http://jsperf.com/sorting-algorithm-comparison" rel="nofollow">research</a> about Javascript sorting algorithms performance comparison, and found unexpected results. Bubble sort provided much better performance than others such as Shell sort, Quick sort and a native Javascript functionality. Why does this happen? Maybe I'm wrong in my performance testing method?</p> <p>You can find my research results <a href="http://jsperf.com/sorting-algorithm-comparison" rel="nofollow">here</a>.</p> <p>Here are some algorithm implementation examples:</p> <pre><code> /** * Bubble sort(optimized) */ Array.prototype.bubbleSort = function () { var n = this.length; do { var swapped = false; for (var i = 1; i &lt; n; i++ ) { if (this[i - 1] &gt; this[i]) { var tmp = this[i-1]; this[i-1] = this[i]; this[i] = tmp; swapped = true; } } } while (swapped); } /** * Quick sort */ Array.prototype.quickSort = function () { if (this.length &lt;= 1) return this; var pivot = this[Math.round(this.length / 2)]; return this.filter(function (x) { return x &lt; pivot }).quickSort().concat( this.filter(function (x) { return x == pivot })).concat( this.filter(function (x) { return x &gt; pivot }).quickSort()); } </code></pre>