I'm running a small game in pygame for which I need a constant delay between each iteration of the main loop. Altough I locked the FPS count at 60 with pygame.Clock.tick_busy_loop(), I observe a variation in delay (around 4 milliseconds per loop). One of my function should be bugged, but I have troubles finding which one.
I used a %prun on my main loop with Ipython, and these are the results :
2264 function calls in 5.439 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
322 4.401 0.014 4.401 0.014 {method 'tick' of 'Clock' objects}
322 0.730 0.002 0.730 0.002 {pygame.display.flip}
1 0.228 0.228 0.228 0.228 {pygame.base.quit}
1 0.034 0.034 0.034 0.034 {method 'blit' of 'pygame.Surface' objects}
1 0.028 0.028 5.439 5.439 main.py:9(main)
323 0.014 0.000 0.014 0.000 {pygame.event.get}
323 0.002 0.000 0.016 0.000 lib.py:26(getInput)
322 0.001 0.000 0.036 0.000 lib.py:80(checkEventType)
322 0.001 0.000 0.035 0.000 lib.py:91(instructions)
322 0.000 0.000 0.000 0.000 {method 'get_time' of 'Clock' objects}
1 0.000 0.000 5.439 5.439 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {pygame.mixer.stop}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
2 0.000 0.000 0.000 0.000 {ord}
Is there something in here that could explain a 2-5 millisecond change in delay between each iteration?