Почему мой код Pygame работает быстрее на 32-битной? - PullRequest
0 голосов
/ 01 мая 2019

У меня установлены как Python 3.7.3, 32-битная версия, так и Python 3.7.3, 64-битная версия.Запуск этого короткого скрипта pygame в обеих версиях python приводит к тому, что 32-битная версия работает намного быстрее.В чем причина этого?

Я запустил следующий код одновременно на python37 64bit, pythonw37 64bit, python37 32bit и pythonw37 32bit, и частота кадров оставалась стабильно намного выше в 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()
...