我同时安装了python 3.7.3 32位和python 3.7.3 64位。在两个版本的python上运行此简短的pygame脚本会导致以32位运行的版本快得多。是什么原因呢?
我在python37 64位,pythonw37 64位,python37 32位和pythonw37 32位上同时运行以下代码,并且在32位版本上,帧速率始终保持更快的速度。
我想理解为什么代码在32位上执行时会明显更快,如果有什么期望的话。
import sys
import time
import pygame
from pygame.locals import *
pygame.init()
SIZE = WIDTH, HEIGHT = (640, 390)
WHITE = (255, 255, 255)
BASE_COLOR = (0, 0, 0)
MAX_FPS = 0
screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()
courier12 = pygame.font.SysFont("Courier", 12)
frame_count = 0
frame_rate = 0
t0 = time.time()
update_rects = list()
version_text = courier12.render(f"{sys.version}", True, WHITE)
first = True
running = True
while running:
dt = clock.tick(MAX_FPS) / 1000
# handle input
for event in pygame.event.get():
if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
running = False
# update
frame_count += 1
if frame_count % 500 == 0:
t1 = time.time()
frame_rate = 500 / (t1-t0)
t0 = t1
# draw
screen.fill(BASE_COLOR)
version_rect = screen.blit(version_text, (10, 18))
if first:
update_rects.append(version_rect)
first = False
fps_text = courier12.render(f"{frame_count:0>8}, {frame_rate:.2f} fps", True, WHITE)
update_rects.append(screen.blit(fps_text, (10, 5)))
# render to screen
pygame.display.update(update_rects)
update_rects.clear()
pygame.quit()
sys.exit()