sort-algorithms (v24)

Revision 24 of this benchmark created on


Description

Comparing native, bubble, insertion, selection, merge, adaptive merge, and quick sort algorithms on a random array.

Preparation HTML

<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/common.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/bubble-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/insertion-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/merge-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/adaptive-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/quick-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/selection-sort.js">
</script>

Setup

// Generate array with 10,000 random integers.
    testArrayLength = 1000;
    var unsortedTestArray = new Array(testArrayLength);
    for (var i = 0; i < testArrayLength; i++) {
      unsortedTestArray[i] = Math.floor(Math.random()*100000);
    }
    var sortedTestArray = unsortedTestArray.clone().sort(function compareNumbers(a, b) {
      return a - b;
    });

Teardown


    if (!unsortedTestArray.compare(sortedTestArray)) {
       throw new Error("Array was not sorted");
    }
  

Test runner

Ready to run.

Testing in
TestOps/sec
Native
unsortedTestArray.sort(function compareNumbers(a, b) {
  return a - b;
});
ready
BubbleSort
aij.bubbleSort(unsortedTestArray);
ready
InsertionSort
aij.insertionSort(unsortedTestArray);
ready
SelectionSort
aij.selectionSort(unsortedTestArray);
ready
QuickSort
aij.quickSort(unsortedTestArray);
ready
AdaptiveSort
unsortedTestArray = aij.adaptiveSort(unsortedTestArray);
ready
MergeSort
unsortedTestArray = aij.mergeSort(unsortedTestArray);
ready

Revisions

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