sorting algorithms

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
insertion sort
var insertionSort = function () {
    var A = [5,8,3,7,2,1,0];
    for (i=1; i<A.length; i++) {
        var item = A[i];
        var hole = i;
    
        while (hole > 0 && A[hole - 1] > item) {
            A[hole] = A[hole -1];
            hole = hole - 1;
        }
        A[hole] = item;
    }
}
insertionSort();
ready
bubble sort
var bubbleSort = function() {
    var A = [5,8,3,7,2,1,0];
    var swapped;
    do {
        swapped = false;
        for (i=1; i<A.length; i++) {
            if (A[i-1] > A[i]) {
                var item = A[i-1];
                A[i-1] = A[i];
                A[i] = item;
                swapped = true;
            }
        }
    } while (swapped);
}
bubbleSort();
ready

Revisions

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