Testing perfomance for most classic sorting algorithms in Python
Testing perfomance of classic sorting algorithms in Python.
python [-O] SortTest.py [[-v]|[-vv]]
Where:
NumPy
+++ Case 01:
This is built in Python sort function
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 0.003 seconds.
+++ Case 02:
Shell sort algorithm -- one of the fastest
Author: Donald Lewis Shell
Performance: O(NlogN)
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 0.089 seconds.
+++ Case 03:
Quick sort algorithm -- the fastest, but deep level of recursion needed
Performance: O(NlogN), recursion level ~ N
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 0.052 seconds.
+++ Case 04:
Bubble sorting algorithm -- is a simplest of sorting algorithms. Classic variant.
Perfomance: O(N**2)
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 1.321 seconds.
+++ Case 05:
Bubble sorting algorithm -- is a simplest of sorting algorithms. Variant with enumerate() usage.
Perfomance: O(N**2)
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 1.810 seconds.
+++ Case 06:
Cocktail shaker sorting alogorithm -- improoved bubble sort
Perfomance: O(N**2)
The sample code was taken from here: https://cutt.ly/qrxDTBr
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 1.594 seconds.
+++ Case 07:
Insertion sorting algorithm -- standard realisation
Perfomance: O(N**2)
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 0.608 seconds.
+++ Case 08:
Insertion sorting algorithm -- my custom Python-specific realisation
Perfomance: O(N**2)
The best performance time among insertions algorithms in python
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 0.127 seconds.
+++ Case 09:
Gnome sorting algorithm
Perfomance: O(N**2)
Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
Time elapsed: 1.284 seconds.
+++ S U M M A R Y +++
The best sorting algorithm is 'sortarray_quick()'
With total time=0.052 seconds for array size=500 and 20 iterations.
An0ther0ne