-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tests.py
164 lines (134 loc) · 4.59 KB
/
Tests.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import time
import collections as dq
class Node:
def __init__(self, state, depth, action, parent, cost):
self.state = state
self.depth = depth
self.action = action
self.parent = parent
self.cost = cost
def stacks(self):
pila = []
times = []
average = 0
increase = 20000
for i in range(1, 50, 1):
start_time = time.time()
for j in range(0, increase, 1):
state = j
depth = j
action = j
parent = j
cost = j
pila.append(Node(state, depth, action, parent, cost))
while pila:
pila.pop()
increase += 20000
average += (time.time() - start_time)
times.append(time.time() - start_time)
average /= 50
biggest = times[0]
smallest = times[0]
for i in range(0,len(times),1):
if times[i] > biggest:
biggest = times[i]
if times[i] < smallest:
smallest = times[i]
print ("\n\nSmallest time for Stacks: " + str(smallest) + "\nBiggest time for Stacks: " + str(biggest) +\
"\nAverage for Stacks: " + str(average))
def queues(self):
cola = dq.deque()
times = []
average = 0
increase = 20000
for i in range(1, 50, 1):
start_time = time.time()
for j in range(0, increase, 1):
state = j
depth = j
action = j
parent = j
cost = j
cola.append(Node(state, depth, action, parent, cost))
while cola:
cola.popleft()
increase += 20000
average += (time.time() - start_time)
times.append(time.time() - start_time)
average /= 50
biggest = times[0]
smallest = times[0]
for i in range(0, len(times), 1):
if times[i] > biggest:
biggest = times[i]
if times[i] < smallest:
smallest = times[i]
print ("\n\nSmallest time for Queues: " + str(smallest) + "\nBiggest time for Queues: " + str(biggest) + \
"\nAverage for Queues: " + str(average))
def arrays(self):
array = []
times = []
average = 0
increase = 20000
for i in range(1, 50, 1):
start_time = time.time()
for j in range(0, increase, 1):
state = j
depth = j
action = j
parent = j
cost = j
array.append(Node(state, depth, action, parent, cost))
while array:
array.pop()
increase += 20000
average += (time.time() - start_time)
times.append(time.time() - start_time)
average /= 50
biggest = times[0]
smallest = times[0]
for i in range(0, len(times), 1):
if times[i] > biggest:
biggest = times[i]
if times[i] < smallest:
smallest = times[i]
print ("\n\nSmallest time for Arrays: " + str(smallest) + "\nBiggest time for Arrays: " + str(biggest) + \
"\nAverage for Arrays: " + str(average))
def dictionaries(self):
diccionario = {}
times = []
average = 0
increase = 20000
for i in range(1, 50, 1):
start_time = time.time()
for j in range(0, increase, 1):
state = j
depth = j
action = j
parent = j
cost = j
diccionario[j] = [Node(state, depth, action, parent, cost)]
for j in range(0, increase, 1):
del diccionario[j]
increase += 20000
average += (time.time() - start_time)
times.append(time.time() - start_time)
average /= 50
biggest = times[0]
smallest = times[0]
for i in range(0, len(times), 1):
if times[i] > biggest:
biggest = times[i]
if times[i] < smallest:
smallest = times[i]
print ("\n\nSmallest time for Dictionaries: " + str(smallest) + "\nBiggest time for Dictionaries: " + str(biggest) + \
"\nAverage for Dictionaries: " + str(average))
def main(self):
jaja = Node(1,1,1,1,1)
jaja.stacks()
jaja.arrays()
jaja.queues()
jaja.dictionaries()
if __name__ == "__main__":
jaja = Node(1,1,1,1,1)
jaja.main()