sort

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    mysort = function (arr) {
        for (var i = 0 ; i < arr.length ; i++) {
                var n = arr[i];
               
                for (var j = i+1 ; j < arr.length ; j++) {
                        if (arr[j] < n) {
                                arr[i] = arr[j];
                                arr[j] = n;
                                n = arr[i];
                                j = i + 1;
                        }
                }
        }
       
        return arr;
    }
   
    function sortBubble(data) {
        var tmp;
     
        for (var i = data.length - 1; i > 0; i--) {
            for (var j = 0; j < i; j++) {
                if (data[j] > data[j+1]) {
                    tmp = data[j];
                    data[j] = data[j+1];
                    data[j+1] = tmp;
                }
            }
        }
        return data;
    }
};
</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
native sort
[5,2,4,6,7,1,3,6,3,2,6,8,6,4,5,4,5,2,5,7,3,9,4,0,4,2,1,3,5,6,9].sort();
pending…
my sort
mysort([5,2,4,6,7,1,3,6,3,2,6,8,6,4,5,4,5,2,5,7,3,9,4,0,4,2,1,3,5,6,9])
pending…
bubble sort
sortBubble([5,2,4,6,7,1,3,6,3,2,6,8,6,4,5,4,5,2,5,7,3,9,4,0,4,2,1,3,5,6,9])
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment