Hi, I'm trying to get the equivalent of arm64 rdtsc on the playdate. I've tried a few of the methods referenced here: embedded - Cycle counter on ARM Cortex M4 (or M3)? - Stack Overflow and tried to use the CoreSight registers, all of which seem to be crashing the playdate due to out of bounds access or requirement for elevated permissions or something.
Programming for embedded arm is new to me, any tips on getting a cycle count?
The getElapsedTime() function uses the DWT->CYCCNT register to implement a fairly accurate timer:
float playdate->system->getElapsedTime(void)
Returns the number of seconds since playdate.resetElapsedTime() was called. The value is a floating-point number with microsecond accuracy.
"microsecond accuracy" there is roughly speaking. Since it returns a floating point value the accuracy depends on how large that value gets, but there's nothing in the code limiting accuracy to 1 uS. Calling resetElapsedTime() before the code you're measuring then getElapsedTime() right after should give you a very accurate measure of execution time, and with some testing you can figure out how much of that is overhead of the reset/getElapsedTime() calls themselves and adjust for that.
This is still a bit coarser grained that I'd like for my Very Important Benchmark I'd like to run, but I can probably make it work. If you're able to toss a direct wrapper into the next SDK like getElapsedTimeCycles or something with a better name, that'd be awesome.