If you aren’t careful (and even sometime when you are) realtime games written in Python sometimes hit speed problems and require some profiling to bring them to a playable speed. Typically, I would use the Python standard library’s “profile” module to find “hot” functions which are stealing all the CPU cycles. Today I discovered another way.
timeit my_slightly_sluggish_function(x, y)
timeit maybe_a_faster_function(x, y)
and get average execution time values over many replicates of each function call, like:
100000 loops, best of 3: 8.9 µs per loop
100000 loops, best of 3: 4.9 µs per loop
Interesting how programming for games and programming for scientific number crunching often have the same requirements and boil down to using similar techniques.