[C SDK] High resolution timer has only millisecond precision

In the C SDK playdate->system->getElapsedTime() seems to return results that are based on milliseconds and not microseconds as described in the documentation. You cannot get value below 1ms. The issue is only when running on the console.

The equivalent function in the lua SDK is more precise and work as expected.


Still occurring with SDK 1.11.1.

This should be resolved in the next release.


I've confirmed it's fixed with 1.12.0 on the device. :+1:



Although it is now possible to get a value with a float, the timer value may be swapped back and forth when the value is obtained in succession.

static int update(void* userdata)
    PlaydateAPI* pd = userdata;


    float t1 = pd->system->getElapsedTime();
    for (int i = 0; i < 100; ++i)
        float t2 = pd->system->getElapsedTime();
        if (t1 > t2)
            pd->system->logToConsole("ERR(%2d): t1:%.5f > t2:%.5f", i, t1, t2);
        pd->system->drawFPS(0, 0);
        t1 = t2;

    return 1;

This is a sample source.

In this case, t1 <= t2 should be the case, but t1 > t2 may be the case only when executed on a device.

This does not occur in the simulator.

Curiously, commenting out pd->system->drawFPS() prevents this from happening.

HDTimerTest.zip (3.9 KB)

A sample reproduction test is attached.

$ rake build:simulator:debug
$ rake build:device:debug
$ rake run

This procedure will start the simulator, so transfer it directly to the device and check the console log.

Best regards.

1 Like

Thanks for the test case, I have a fix ready to go, and it will make it into a release in the near future.