-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheappqueue.py
39 lines (32 loc) · 873 Bytes
/
heappqueue.py
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
from HeapPriorityQueue import HeapPriorityQueue
import random
import matplotlib.pyplot as plt
import pandas as pd
import time
def test_heap(n):
measures = []
summa = 0
a = HeapPriorityQueue()
sample = random.sample(range(1, 1000*n), n)
for i in range(n):
for ele in sample:
a.add(i,ele)
for i in range(n):
start = time.time()
a.remove_min()
end = time.time() # nanoseconds
measures.append(end-start)
for i in measures:
summa += i
return (n,summa/len(measures),max(measures))
def report_results():
result_list = []
for i in range(10000,1000001, 10000):
result_list.append(test_heap(i))
return result_list
result_list = report_results()
df = pd.DataFrame(result_list, columns = ['n', 'avg', 'max'])
print(df)
df.plot(x ='n', y='avg', kind = 'line')
df.plot(x ='n', y='max', kind = 'line')
plt.show()