Sort array

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function insertSort(array, comparator) {
        for (var i = 1; i < array.length; i++) {
            var tmp = array[i],
                j = i;
   
            while (j > 0 && comparator(array[j - 1], tmp)) {
                    array[j] = array[j - 1];
                    --j;
            }
   
            array[j] = tmp;
        }
   
        return array;
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Insert sort
var arr = [1, 3, 5, 2, 4, 8, 7];
insertSort(arr, function(a, b) {
  return a - b;
});
pending…
Array sort
var arr = [1, 3, 5, 2, 4, 8, 7];
arr.sort(function(a, b) {
  return a - b;
});
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment