📜 ⬆️ ⬇️

Benchmark 14 sorting algorithms on arrays with different dimensions and content

This article focuses on the sorting benchmark written in PHP.

A total of 14 algorithms are presented:


')
More about algorithms
quickSort - Quick sort *
countingSort - Sort by counting *
combSort - Sort by comb *
heapSort - Sort by heap *
mergeSort - Merge Sort *
shellSort - Shell Sort *
selectionSort - Sort by selection *
insertSort - Sort Inserts *
gnomeSort - “Gnome” sorting *
combinedBubbleSort - Modified Bubble Sort
cocktailSort - Shaker sort *
bubbleSort - Bubble Sort *
oddEvenSort - Odd even sort
bubbleSortWithFlag - Bubble Sort with Permutations Flag



The algorithms are not arranged in alphabetical order, but in order of decreasing their speed when sorting an array of 8 thousand elements.

The dimensions of the arrays used for sorting are:



Also, each measurement was made with a different array filling, transmitted to the sort function:



Each measurement was made three times and the arithmetic average was taken.

Arrays up to thousands of elements


All sorting functions are included in this category.




Arrays of up to 30 thousand elements


This time, the 5 fastest algorithms are involved: sorting by counting, quick sorting, sorting by comb, sorting by heap and sorting by merge.




Arrays of up to 200 thousand elements


This time all the same 5 algorithms are involved: sorting by counting, quick sorting, sorting by comb, sorting by heap and sorting by merge.




Arrays of up to 2,000,000 items


Two algorithms took part in the last run for 2 million elements: sorting by counting and quick sorting.




findings


QuickSort is considered to be a good enough algorithm. CountingSort is very good at small ranges of values, otherwise it does not cope due to lack of memory. Shaker sorting turned out to be a bad choice for random values. "Bubble" and its modifications are not applicable for practical use.

Source code of all algorithms + my results: drive.google.com/file/d/0B5FrhsQAeZwCUmx0dzFjeVdra0E/edit?usp=sharing

Source: https://habr.com/ru/post/221807/


All Articles