-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThreadTest.py
60 lines (49 loc) · 1.65 KB
/
ThreadTest.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
import threading
import time
from VaccineModel import VaccineModel
import sys
class ThreadTest(threading.Thread):
"""docstring for ThreadTest."""
def __init__(self, id, vaccineProb=0):
super(ThreadTest, self).__init__()
self.id = id
self.vaccineProb = vaccineProb
self.results = None
self.simulation = VaccineModel({'probVaccine' : self.vaccineProb/100, 'probDeath' : 0, 'probCure' : 0})
def run(self):
#print(f"{self.id} starting")
self.startTime = time.time()
self.executeFunction()
self.endTime = time.time()
#print(f"{self.id} finished in {self.endTime-self.startTime} seconds")
def executeFunction(self):
self.simulation.buildFirstFrame()
while self.simulation.spread():
pass
self.results = self.simulation.trueResults
nbIter = 24
if __name__ == '__main__' and sys.argv[1] == "thread":
print("STARTING TIME")
start = time.time()
results = []
for i in range(nbIter):
results.append(ThreadTest(i))
print(i)
for i in range(nbIter):
test = time.time()
results[i].start()
print(i, time.time()-test)
print("FINISHED")
print(" Time took : ", time.time()-start)
if __name__ == '__main__' and sys.argv[1] == "normal":
print("STARTING TIME")
start = time.time()
results = []
for i in range(nbIter):
results.append(VaccineModel({'probVaccine' : i/100, 'probDeath' : 0, 'probCure' : 0}))
results[-1].buildFirstFrame()
while results[-1].spread():
pass
print(i)
print("FINISHED")
print(" Time took : ", time.time()-start)