-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformancetest.py
91 lines (71 loc) · 2.44 KB
/
performancetest.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
import threading
import time
import pyautogui
from piecepicker import AutoPiecePicker, SequentialPiecePicker
from tetrisgame import TetrisGame, GameType
from tetrosolver import TetroSolver, TetroConfig
from pycallgraph2 import PyCallGraph
from pycallgraph2.output import GraphvizOutput
__exit = False
PROFILING = False
if PROFILING:
PERFORMANCE_PIECES = 1000
else:
PERFORMANCE_PIECES = 10000
COMPARE_TIME = 4.273208379745483
# First time: 12.4905264377594
def testPerformanceMethod(solver):
global __exit
global PROFILING
pieces = 0
startTime = time.time()
percentageCheck = PERFORMANCE_PIECES / 20
if PROFILING:
with PyCallGraph(output=GraphvizOutput()):
while True:
if pieces % percentageCheck == 0:
print(f"{100 * (pieces / PERFORMANCE_PIECES)} %")
if __exit:
break
if pieces >= PERFORMANCE_PIECES:
break
if not solver.check():
break
pieces += 1
else:
while True:
if pieces % percentageCheck == 0:
print(f"{100 * (pieces / PERFORMANCE_PIECES)} %")
if __exit:
break
if pieces >= PERFORMANCE_PIECES:
break
if not solver.check():
break
pieces += 1
endTime = time.time()
print(f"Finished performance test with pieces: {PERFORMANCE_PIECES}")
print(f"Rows cleared: {solver.getGameScore()}")
print(f"Time: {endTime - startTime}")
print(f"Compare time: {COMPARE_TIME}")
def performanceThread():
global __exit
game = TetrisGame()
game.piecePicker = SequentialPiecePicker()
solverConfig = TetroConfig()
solverConfig.log = False
solverConfig.fieldConfig.log = False
solverConfig.fieldConfig.FLAT_FACTOR = 1.1228687283916032
solverConfig.fieldConfig.HOLE_FACTOR = 5.193397373397724
solverConfig.fieldConfig.HEIGHT_FACTOR = 0.16380901479600363
solverConfig.fieldConfig.LINE_FACTOR = 1.2577257145153835
solver = TetroSolver(game, solverConfig)
testPerformanceMethod(solver)
if __name__ == "__main__":
runThread = threading.Thread(target=performanceThread)
runThread.start()
if PROFILING:
pyautogui.alert(text=f"Click here to quit profiling", title='Performance test',
button='Exit')
__exit = True
runThread.join()