In this article I will tell you about the benchmark of sorting algorithms, written on PHP.
There are 14 algorithms presented:

Algorithms are not alphabetically ordered, but in order of their performance speed descending when sorting an array of 8 thousand elements.

The following arrays dimensions, used for sorting, are presented:

Each measurement was performed with different array filling, which is passed to sorting function.

Each measurement has been performed three times and an arithmetic mean has been taken

Arrays of up to 1000 elements

All sorting functions are involved in this category.

Arrays of up to 30 thousand elements

In this case 5 the fastest algorithms are involved: counting, quick, comb, heap and merge sorts.

Arrays of up to 200 thousand elements

In this case the same 5 algorithms are involved: counting, quick, comb, heap and merge sorts.

Arrays of up to 2 million elements

In the last round of 2 million elements two algorithms were involved: count sort and quick sort.


QuickSort is rightfully considered quite a good algorithm. CountingSort is really good at small value ranges; otherwise it can’t manage due to low memory. Cocktail sort proved to be a bad choice for random values. Bubble sort and its modifications are not applicable to practical use.

Source code of all algorithms + results:

While a fun exercise, use the built in sort function. Building a sort function in interpreted PHP code will never be faster than the C variant that sort() employs.

Subscribe to Kukuruku Hub

Or subscribe with RSS


Very nice! Check out the visualization of sorting algorithms:
Kukuruku Hub
Yes, I saw that, looks amazing. It seems they only have two algorithms though.

Read Next