Optimized merge sort faster than quicksort
<p><a href="http://jsperf.com/optimized-mergesort-versus-quicksort" rel="nofollow noreferrer">http://jsperf.com/optimized-mergesort-versus-quicksort</a></p>
<p>Why does this half buffer merge sort work as fast as quicksort?</p>
<p>QuickSort is:</p>
<ol>
<li>In-Place although it takes up <code>log(n)</code> recursions (stack space)</li>
<li>Cache-Friendly</li>
</ol>
<p>This half buffer merge sort:</p>
<ol>
<li>Uses an <code>n/2</code> Buffer to do merges.</li>
<li>Uses <code>log(n)</code> recursions.</li>
<li>Makes fewer comparisons.</li>
</ol>
<p>My question is, why is the half buffer merge sort matching the speed of QuickSort in this scenario?
Plus, is there anything I'm doing wrong to the quickSort that makes it slower?</p>
<pre><code>function partition(a, i, j) {
    var p = i + Math.floor((j - i) / 2);
    var left = i + 1;
    var right = j;
    swap(a, i, p);
    var pivot = a[i];
    while (left &lt;= right) {
        while (builtinLessThan(a[left], pivot)) {
            ++left;
        }
        while (builtinLessThan(pivot, a[right])) {
            --right;
        }
        if (left &lt;= right) {
            swap(a, left, right);
            ++left;
            --right;
        }
    }
    swap(a, i, right);
    return right;
};

function quickSort(a, i, j) {
    var p = partition(a, i, j);
    if ((p) - i &gt; j - p) {
        if (i &lt; p - 1) {
            quickSort(a, i, p - 1);
        }
        if (p + 1 &lt; j) {
            quickSort(a, p + 1, j);
        }
    } else {
        if (p + 1 &lt; j) {
            quickSort(a, p + 1, j);
        } if (i &lt; p - 1) {
            quickSort(a, i, p - 1);
        }
    }
};
</code></pre>