项目作者: An0ther0ne

项目描述 :
Testing perfomance for most classic sorting algorithms in Python
高级语言: Python
项目地址: git://github.com/An0ther0ne/PySort.git
创建时间: 2020-01-14T13:21:36Z
项目社区:https://github.com/An0ther0ne/PySort

开源协议:

下载


PySort

Testing perfomance of classic sorting algorithms in Python.

Synopsis

  1. python [-O] SortTest.py [[-v]|[-vv]]

Where:

  • -O : turn DEBUG flag to off
  • -v : verbose level 1
  • —vv : verbose level 2

    Explanation

    This program designed for purpose of testing performance and accuracy of various sorting algorithms.
    We wraps with decorator each of those algorithm. And decorator runs for us the specified number of tests for each sorting algorithm, notice result (passed or not) of it and calcuate total elapsed time for all amount of tests in this case.
    The testing procedure is to check all array elements are sorted in ascending order. Each time after this check an array is randomized again.
    If at least one of test is fail – wrapper skip all following and return the failed state.
    For total time calculation purpose only effective runtime of each successfully completed sorting function counts.
    At the end of all tests, name of the fastest algorithm is determined and displayed.
    For comparison, also shown a total time for built into Python sorting algorithm, but which is not considered in the summary championship result, because it is not implemented by the Python language itself.

Files:

Requirements

  • Python 3.x
  • NumPy

    Output

    +++ Case 01:

    1. This is built in Python sort function
    2. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
    3. Time elapsed: 0.003 seconds.

+++ Case 02:

  1. Shell sort algorithm -- one of the fastest
  2. Author: Donald Lewis Shell
  3. Performance: O(NlogN)
  4. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  5. Time elapsed: 0.089 seconds.

+++ Case 03:

  1. Quick sort algorithm -- the fastest, but deep level of recursion needed
  2. Performance: O(NlogN), recursion level ~ N
  3. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  4. Time elapsed: 0.052 seconds.

+++ Case 04:

  1. Bubble sorting algorithm -- is a simplest of sorting algorithms. Classic variant.
  2. Perfomance: O(N**2)
  3. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  4. Time elapsed: 1.321 seconds.

+++ Case 05:

  1. Bubble sorting algorithm -- is a simplest of sorting algorithms. Variant with enumerate() usage.
  2. Perfomance: O(N**2)
  3. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  4. Time elapsed: 1.810 seconds.

+++ Case 06:

  1. Cocktail shaker sorting alogorithm -- improoved bubble sort
  2. Perfomance: O(N**2)
  3. The sample code was taken from here: https://cutt.ly/qrxDTBr
  4. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  5. Time elapsed: 1.594 seconds.

+++ Case 07:

  1. Insertion sorting algorithm -- standard realisation
  2. Perfomance: O(N**2)
  3. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  4. Time elapsed: 0.608 seconds.

+++ Case 08:

  1. Insertion sorting algorithm -- my custom Python-specific realisation
  2. Perfomance: O(N**2)
  3. The best performance time among insertions algorithms in python
  4. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  5. Time elapsed: 0.127 seconds.

+++ Case 09:

  1. Gnome sorting algorithm
  2. Perfomance: O(N**2)
  3. Sorting tests : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, Passed.
  4. Time elapsed: 1.284 seconds.

+++ S U M M A R Y +++

  1. The best sorting algorithm is 'sortarray_quick()'
  2. With total time=0.052 seconds for array size=500 and 20 iterations.

LINKS

  1. DONALD E. KNUTH “The Art Of Computer Programming, Volume 3: Sorting and Searching.”
  2. WIKI Sorting algorithm
  3. WIKI explanation for Cocktail shaker sorting

AUTHOR

An0ther0ne