-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathui_element_creation_speed_test.py
113 lines (88 loc) · 3.55 KB
/
ui_element_creation_speed_test.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
from sys import stdout
from pstats import Stats
from cProfile import Profile
import pygame
import pygame_gui
import os
# (182 x rounded rectangles)
# in 0.42
# --------
# Button creation time taken: 0.092 seconds.
# Clear and recreation time taken: 0.088 seconds.
# in 0.55
# --------
# Button creation time taken: 0.21 seconds.
# Clear and recreation time taken: 0.229 seconds.
# in 0.56
# --------
# Button creation time taken: 0.078 seconds.
# Clear and recreation time taken: 0.079 seconds.
# in 0.57 - got slower again, dang.
# --------
# Button creation time taken: 0.096 seconds.
# Clear and recreation time taken: 0.095 seconds.
# in 0.6.10
# ---------
# Button creation time taken: 0.062 seconds.
# Clear and recreation time taken: 0.057 seconds.
print(os.getcwd())
pygame.init()
pygame.display.set_caption('Button Theming Test')
window_surface = pygame.display.set_mode((800, 600))
manager = pygame_gui.UIManager((800, 600), 'data/themes/quick_theme.json')
clock = pygame.time.Clock()
background = pygame.Surface((800, 600))
background.fill(manager.get_theme().get_colour('dark_bg'))
load_time_1 = clock.tick()
test_container = pygame_gui.core.UIContainer(pygame.Rect(0, 0, 800, 600),
manager=manager)
def create_buttons():
button_row_width = 50
button_row_height = 40
spacing = 10
for j in range(1, 15):
for i in range(1, 14):
position = (i * spacing + ((i - 1) * button_row_width),
(j * spacing + ((j - 1) * button_row_height)))
pygame_gui.elements.UIButton(relative_rect=pygame.Rect(position,
(button_row_width,
button_row_height)),
text=str(i)+',' + str(j),
manager=manager,
container=test_container,
object_id='#'+str(i) + str(j))
load_time_2 = clock.tick()
print('Button creation time taken:', load_time_2 / 1000.0, 'seconds.')
test_container.clear()
for j in range(1, 15):
for i in range(1, 14):
position = (i * spacing + ((i - 1) * button_row_width),
(j * spacing + ((j - 1) * button_row_height)))
pygame_gui.elements.UIButton(relative_rect=pygame.Rect(position,
(button_row_width,
button_row_height)),
text=str(i)+',' + str(j),
manager=manager,
container=test_container,
object_id='#'+str(i) + str(j))
load_time_3 = clock.tick()
print('Clear and recreation time taken:', load_time_3 / 1000.0, 'seconds.')
create_buttons()
is_running = True
while is_running:
time_delta = clock.tick(60)/1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
manager.process_events(event)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.update()
if __name__ == '__main__':
profiler = Profile()
profiler.runcall(create_buttons)
stats = Stats(profiler, stream=stdout)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats()