gruns / icecream

🍦 Never use print() to debug again.
MIT License
9.21k stars 187 forks source link

First call to ic() can take significant amounts of time in Pygame games, especially in debug mode #166

Open StephenPeringer opened 1 year ago

StephenPeringer commented 1 year ago

I've just started using ic(), and I've noticed that in the right context, it takes a too long to run.

This is the code I used to measure execution times:

from time import time
from icecream import ic

start = time()
ic.format("")
end = time()
print(f"time: {end - start}")

I ran this code in two different Pygame games, each in both Run and Debug modes, all in PyCharm. One game is a "Hello, World!" game, and the other is a more fully developed arcade game. I ran them each several times. These are all typical results, in descending order of problematic:

Fuller game, Debug mode

time: 1.7278175354003906

Fuller game, Run mode

time: 0.3357973098754883

Hello, World!, Debug mode

time: 0.27829909324645996

Hello, World!, Run mode

time: 0.12203741073608398

This kind of lag only happens the first time ic() is called; further calls are in the range of 0.001s to 0.005s. I understand from reading other bug reports that you're not focused on speed, but 1.7 seconds is too long to wait each time a developer tweaks something and starts the game up to test it.