This repository has been archived by the owner on Mar 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance.py
98 lines (75 loc) · 2.29 KB
/
performance.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from main import *
from random import *
from time import *
avl1 = open("performanceData/performanceAvl1.txt", "w+")
avl2 = open("performanceData/performanceAvl2.txt", "w+")
dic1 = open("performanceData/performanceDic1.txt", "w+")
dic2 = open("performanceData/performanceDic2.txt", "w+")
def randomList(lenght):
minimo = 88
massimo = 12454
b = 9
check = True
listRandom = []
for i in range(lenght):
num = choice([randint(minimo,massimo), choice([randint(minimo-10000, minimo),
randint(massimo,massimo+10000)])])
if num not in listRandom:
listRandom.append(num)
else:
while check:
num = choice([randint(minimo,massimo), choice([randint(minimo-10000, minimo),
randint(massimo,massimo+10000)])])
if num not in listRandom:
listRandom.append(num)
check = False
check = True
#print(listRandom)
#print(len(listRandom))
return listRandom
def testPerformance(size):
for n in range(0, size+1, 100):
avlll = AvlLinkedList(88,12454,9)
dic = {}
if n == 0:
continue
print(n)
listRandom = randomList(n)
#insert
for elem in listRandom:
avlll.insert(elem, str(elem))
for elem in listRandom:
dic[elem] = str(elem)
#/insert
#avl-search and avg times
start = time()
for elem in listRandom:
avlll.search(elem)
tempo = time() - start
#end
avl1.write("{}\t{}\n".format(n, tempo/n))
#dictionary-search and avg times
start = time()
for elem in listRandom:
dic[elem]
tempo = time() - start
dic1.write("{}\t{}\n".format(n, tempo/n))
#end
#avl-delete time
start = time()
for elem in listRandom:
avlll.delete(elem)
tempo = time() - start
#end
avl2.write("{}\t{}\n".format(n, tempo/n))
#dictionary-delete time
start = time()
for elem in listRandom:
dic.pop(elem)
tempo = time() - start
dic2.write("{}\t{}\n".format(n, tempo/n))
#end
avl1.close()
avl2.close()
dic1.close()
dic2.close()