Difficult-Rocket/performance_test/test_speed_of_sprite.py

40 lines
873 B
Python
Raw Normal View History

2021-06-26 14:15:33 +08:00
import time
import pyglet
window = pyglet.window.Window(resizable=True)
2021-07-08 20:42:22 +08:00
ball_image = pyglet.image.load('D:/github/DR/textures/Atmospheres.png') # 可自定义材质
2021-06-26 14:15:33 +08:00
batch = pyglet.graphics.Batch()
ball_sprites = []
start_t = time.time()
2021-07-08 20:42:22 +08:00
for i in range(10000): # 可自定义数量
x, y = i * 30, 50
2021-06-26 14:15:33 +08:00
ball_sprites.append(pyglet.sprite.Sprite(ball_image, x, y, batch=batch))
2021-07-08 20:42:22 +08:00
ball_sprites[i - 1].visible = False
2021-06-26 14:15:33 +08:00
end_t = time.time()
2021-07-08 20:42:22 +08:00
print(start_t, end_t, end_t - start_t)
a = 1
2021-06-26 14:15:33 +08:00
@window.event
def on_draw():
start_t = time.time()
2021-07-08 20:42:22 +08:00
if a == 0:
for x in ball_sprites:
if x.visible:
x.draw()
elif a == 1:
2021-06-26 14:15:33 +08:00
for x in ball_sprites:
x.draw()
else:
batch.draw()
end_t = time.time()
2021-07-08 20:42:22 +08:00
print(start_t, end_t - start_t)
2021-06-26 14:15:33 +08:00
print(end_t, pyglet.clock.get_fps(), 'fps')
2021-07-08 20:42:22 +08:00
2021-06-26 14:15:33 +08:00
pyglet.app.run()