mac运行python速度慢_python-3.x – Pygame简单循环在Mac上运行得非常慢
E:在OS X和
Linux上測試相同后,我可以確認以下內容只發生在OS X上.在Linux上,它實際上以千fps運行,因為我碰巧想知道.任何解釋?感謝TextMate,我更喜歡在Mac上進行開發.
這是一個幾乎沒有任何作用的簡單循環,并且運行速度非常慢.有人可以解釋為什么嗎FPS平均值略高于30,每次通過循環需要30多分鐘.窗口大小似乎根本不會影響這一點,因為即使設置像(50,50)這樣的小窗口大小也具有相同的fps.
我發現這很奇怪,我希望任何現代硬件都可以為這樣一個簡單的循環做一千fps,即使我們每次都更新每個像素.從配置文件中我可以看到{內置方法get}和{內置方法更新}組合似乎每次調用大約需要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()
這是主要功能的cProfile的開頭.
94503 function calls (92211 primitive calls) in 21.011 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.026 0.026 21.011 21.011 new_main.py:34(main)
652 14.048 0.022 14.048 0.022 {built-in method get}
652 5.864 0.009 5.864 0.009 {built-in method update}
1 0.444 0.444 0.634 0.634 {built-in method init}
651 0.278 0.000 0.278 0.000 {built-in method set_caption}
72/1 0.000 0.000 0.151 0.151 :2234(_find_and_load)
72/1 0.000 0.000 0.151 0.151 :2207(_find_and_load_unlocked)
71/1 0.000 0.000 0.151 0.151 :1186(_load_unlocked)
46/1 0.000 0.000 0.151 0.151 :1122(_exec)
46/1 0.000 0.000 0.151 0.151 :1465(exec_module)
74/1 0.000 0.000 0.151 0.151 :313(_call_with_frames_removed)
54/1 0.004 0.000 0.151 0.151 {built-in method exec}
1 0.000 0.000 0.151 0.151 macosx.py:1()
1 0.000 0.000 0.150 0.150 pkgdata.py:18()
25/3 0.000 0.000 0.122 0.041 :1156(_load_backward_compatible)
8/1 0.026 0.003 0.121 0.121 {method 'load_module' of 'zipimport.zipimporter' objects}
1 0.000 0.000 0.101 0.101 __init__.py:15()
1 0.000 0.000 0.079 0.079 config_reader.py:115(build_from_config)
2 0.000 0.000 0.056 0.028 common.py:43(reset_screen)
2 0.055 0.027 0.055 0.027 {built-in method set_mode}
72/71 0.001 0.000 0.045 0.001 :2147(_find_spec)
70/69 0.000 0.000 0.043 0.001 :1934(find_spec)
70/69 0.001 0.000 0.043 0.001 :1902(_get_spec)
92 0.041 0.000 0.041 0.000 {built-in method load_extended}
6 0.000 0.000 0.041 0.007 new_map.py:74(add_character)
6 0.000 0.000 0.041 0.007 new_character.py:32(added_to_map)
6 0.001 0.000 0.041 0.007 new_character.py:265(__init__)
1 0.000 0.000 0.038 0.038 macosx.py:14(Video_AutoInit)
1 0.038 0.038 0.038 0.038 {built-in method InstallNSApplication}
1 0.036 0.036 0.036 0.036 {built-in method quit}
65 0.001 0.000 0.036 0.001 re.py:277(_compile)
49 0.000 0.000 0.036 0.001 re.py:221(compile)
總結
以上是生活随笔為你收集整理的mac运行python速度慢_python-3.x – Pygame简单循环在Mac上运行得非常慢的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: yoyo跑_面对“跑腿服务坑”:悠悠跑腿
- 下一篇: 毒液配音演员透露索尼 PS5 大作《漫威