[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] pygame.display.flip slow



Hi

I'm experiencing very slow frame rates on a particular set up and need some help to understand
what may be causing it.

On this machine, the code below has an avg fram rate of around 45fps.
The profiling output is:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    2.015    2.015 <string>:1(<module>)
        1    0.001    0.001    2.015    2.015 fps_test.py:11(run)
        1    0.000    0.000    2.015    2.015 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 {built-in method builtins.print}
        1    0.000    0.000    0.000    0.000 {built-in method builtins.sum}
      100    1.977    0.020    1.977    0.020 {built-in method pygame.display.flip}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
      100    0.031    0.000    0.031    0.000 {method 'fill' of 'pygame.Surface' objects}
      100    0.000    0.000    0.000    0.000 {method 'get_fps' of 'Clock' objects}
      100    0.006    0.000    0.006    0.000 {method 'tick' of 'Clock' objects}

This is:
Fedora 31
Python 3.7.6
Pygame 1.9.6 (I tried pygame 2.0.0.dev7 and it's the same)

The specs are fine:
Intel(R) Core(TM) i7-5930K CPU @ 3.50GHz

"glxgears" runs happily at 60fps on this machine.
I can run the code below on a on slower machine (my laptop) with the same software config
(F31/Python3.7/Pygame1.9.6)  and easily get the 60fps.

Any pointers to what may be causing this? Oh, a note, the larger the display size,
the slower it gets. 1440x900 is just the size of the laptop screen, so the larger I
could use to compare using the same version of Fedora.

import pygame
pygame.init()
clock = pygame.time.Clock()
screen_flags = 0
screen = pygame.display.set_mode((1440, 900), screen_flags)
pygame.display.set_caption("FPS Test")
print(pygame.display.Info())

def run():
    x = 0
    fps = [0] * 100
    while x < 100:
        screen.fill(pygame.Color(0, 0, 0))
        pygame.display.flip()
        clock.tick(60)
        fps[x] = clock.get_fps()
        x += 1
    print(sum(fps)/100.)
import cProfile
cProfile.run('run()')


Thanks.