E:在OS X和Linux上测试后,我可以确认以下只发生在OS X上.在Linux上,它实际上运行的速度是千fps,因为我碰巧想知道.任何解释?感谢TextMate,我更喜欢在Mac上进行开发.
我发现这很奇怪,我希望任何现代硬件都可以为这样一个简单的循环做一千fps,即使我们每次都更新每个像素.从配置文件中我可以看到,{built-in method get}并且{built-in method update}组合似乎每次通话需要大约30ms的时间,这是否真的是最好的我们可以在不使用脏的情况下出来?
pygame.init()
clock = pygame.time.Clock()
fps = 1000
#milliseconds from last frame
new_time, old_time = None, None
done = False
while not done:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# show fps and milliseconds
if new_time:
old_time = new_time
new_time = pygame.time.get_ticks()
if new_time and old_time:
pygame.display.set_caption("fps: " + str(int(clock.get_fps())) + " ms: " + str(new_time-old_time))
pygame.display.update()
Run Code Online (Sandbox Code Playgroud)
这是主要功能的cProfile的开头.
94503 function calls …Run Code Online (Sandbox Code Playgroud)