I compared the run time of sort and a program I wrote O (n).
Marvel finds the speed of sort almost as close as the program run Time of O (n) written directly in Python
first on the code
test code for sort
Import Random
Import SYS
len_test_arr = Int (sys.argv[1])
Test_arr = [Random.random () for I in Xrange (Len_test_arr)]
Len_test_arr.sort ()
The run instruction for the test time Python test.py 10,10 represents the length of the array, which is used for the duration of the user.
python-written o (n) program
Import Random
Import SYS
def Counting_sort (a):
count = [0]*100
For I in a:
count + = 1
return Count
len_test_arr = Int (sys.argv[1])
Test_arr = [Random.randint (0) for I in Xrange (Len_test_arr)]
Counting_sort (Test_arr)
The run instructions for the test time are the same. The test.py 10,10 represents the length of the array, and only the user is taken.
Results
built-in sort
Data Size | Run time (s)
Ten 0.01
0.014
0.01
10000 0.013
100000 0.065
1000000 0.769
10000000 10.991
python-written o (n) program
Data Size | Run time (s)
Ten 0.01
0.01
0.01
10000 0.02
100000 0.13
1000000 1.1
10000000
How fast is Python's built-in sort