-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunplot.py
More file actions
55 lines (45 loc) · 1.44 KB
/
Copy pathrunplot.py
File metadata and controls
55 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from BogoBogoSort import bogoBogoSort
from BogoSort import bogoSort
from BozoSort import bozoSort
from CommunismSort import communismSort
from MiracleSort import miracleSort
from StalinSort import stalinSort
from SlowSort import slowSort
import numpy as np
import time
import matplotlib
import matplotlib.pyplot as plt
from pick import pick
def time_it(func):
start = time.time()
func()
end = time.time()
#print('sorted list: '+ str(func()))
print('Finished in {} seconds.'.format(end - start))
if alg_name == 'miracleSort':
if func() != None:
return end - start
else:
return 0
else:
return end - start
algsList = [bogoBogoSort, bogoSort, bozoSort, communismSort, miracleSort, stalinSort, slowSort]
title = 'Please choose a algorithm: '
options = ['bogoBogoSort', 'bogoSort', 'bozoSort', 'communismSort', 'miracleSort', 'stalinSort', 'slowSort']
option, index = pick(options, title)
alg_name = str(algsList[index].__name__)
times = []
max_n = int(input('Enter max n: '))
print('\n'+alg_name+ '...')
for i in range(1,max_n+1):
randlist = np.random.randint(0, 100, i).tolist()
print('\n'+'unsorted list: ', randlist)
times.append(time_it(lambda: algsList[index](randlist)))
n = range(1,max_n+1)
fig, ax = plt.subplots()
ax.plot(n, times)
ax.set(xlabel='array length (n)', ylabel='time (s)',
title=alg_name)
ax.grid()
fig.savefig("img/"+alg_name+".png")
plt.show()