sort-algorithms (v46)

Revision 46 of this benchmark created by splitice 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/quickmiddle-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/selection-sort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/flashsort.js">
</script>
<script src="https://rawgithub.com/escherba/algorithms-in-javascript/master/src/heap-sort.js">
</script>

Setup

// Generate array with 10,000 random integers.
    testArrayLength = 64;
    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 (!result.compare(sortedTestArray)) {
       throw new Error("Array was not sorted");
    }
  

Test runner

Ready to run.

Testing in
TestOps/sec
Native
var result = unsortedTestArray.clone().sort(function compareNumbers(a, b) {
  return a - b;
});
ready
InsertionSort
var result = aij.insertionSort(unsortedTestArray.clone());
ready
Heapsort
var result = aij.heapSort(unsortedTestArray.clone());
ready
AdaptiveSort
var result = aij.adaptiveSort(unsortedTestArray.clone());
ready
MergeSort
var result = aij.mergeSort(unsortedTestArray.clone());
ready
QuickSort
var result = aij.quickmiddleSort(unsortedTestArray.clone());
ready
Flashsort
var result = aij.flashSort(unsortedTestArray.clone());
ready

Revisions

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