Hardware: iMac with a 4.2GHz i7, 40 GB of DDR4 RAM, and a Radeon Pro 580 8192 MB
-> Curiously, my updated code posted below ran at only 1.6 FPS on my iMac
I started making a game in pygame that became unusably slow. I discovered that having a larger window decreased the fps significantly, even when nothing was being displayed. To demonstrate this, I created the simple program below. Every iteration, it increases the window size slightly.
At first, the game window (with nothing displayed on it) runs at about 150 fps at 100x100 pixels. By the time it increases to 1000x1000 pixels it's running at just 2 fps.
What am I doing wrong? I will have to give up on making my game if the fps is this low. Thanks for the help.
import pygame, time
pygame.init()
display_width = 100
display_height = 100
win = pygame.display.set_mode((display_width, display_height))
clock = pygame.time.Clock()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
win.fill((0, 0, 0)) #fills over pre-existing elements
pygame.display.update()
clock.tick()
print(clock.get_fps())
display_width += 1
display_height += 1
win = pygame.display.set_mode((display_width, display_height))
print('QUIT')
pygame.quit()
UPDATE: I have been notified that updating the display dimensions every iteration makes this an unfair test for performance. This is why I have updated the code below. This code initializes the window size at 2000x2000 and constantly updates it as a blank screen. However, this still only achieves 6 FPS with nothing even on it. Why is this?
import pygame, time
pygame.init()
display_width = 2000
display_height = 2000
win = pygame.display.set_mode((display_width, display_height))
clock = pygame.time.Clock()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
win.fill((0, 0, 0)) #fills over pre-existing elements
pygame.display.update()
clock.tick()
print(clock.get_fps())
print('QUIT')
pygame.quit()