I’m building a profiler for my game to better understand my speed bottlenecks and have a better understanding where my code is slow.
I’m currently using getElapsedTime for this, but it has a couple of downsides.
It is a float value, meaning it is less accurate the more time it passes. If I want to profile a section of my game that takes a while to get there, the measurements are not really accurate. I can call
resetElapsedTime and that helps, but it makes it harder to add profiling code to the game without messing up code that may use getElapsedTime
Seems like getElapsedTime is using the DWT->CYCCNT register which would be great to use as it is an integer and it doesn’t matter if it wraps around it still gives accurate reading of how many cycles passed without loosing any precision. The problem is that the register is not available in user land and the Playdate crashes when trying to access it.
Windows offers the QueryPerformanceCounter and the QueryPerformanceFrequency API functions to access similar information.