SDL_GetPerformanceFrequency() - Does it ever return a different result?



Is it possible that SDL_GetPerformanceFrequency() can return different values at different times during throughout the execution of my runtime? I.e. do any of the platforms that SDL runs on have a variable performance frequency?

I’m asking to know if its a good idea to cache it once at startup.



On which platforms do you run ?
According to windows documentation

The frequency of the performance counter is fixed at system boot and is consistent across all processors.


Yeah I read that but was wondering about the other platforms. My assumption is it’s the same right now but just wanted to confirm.


Windows was already covered so here’s the SDL code for the other 99.9% of platforms.

    if (!ticks_started) {

    if (has_monotonic_time) {
        return 1000000000;
#elif defined(__APPLE__)
        Uint64 freq = mach_base_info.denom;
        freq *= 1000000000;
        freq /= mach_base_info.numer;
        return freq;
    return 1000000;

mach_base_info gets initialized only once on initialization and can’t change unless the SDL library is somehow reloaded. The Apple documentation doesn’t seem to state it outright, but it’s hinting at the fact that its behavior is the same as Windows. They probably do it on boot too.

The value returned by SDL_GetPerformanceFrequency is not going to change during runtime.

It is possible to configure some systems to use different timer hardware, but I think these usually require a restart.


Thanks for the answers guys! Appreciate the insight.


Having a definite answer to this would still be cool - sure, on Windows
it never changes while the program is running and on the Unix-like
systems it seems to be a compiletime constant anyway (because the
internal timers return real times, usually nanoseconds), but that
doesn’t mean it’s constant on all platforms - unless SDL guarantees it.

Any insight on this, Sam or Ryan (or someone else)?



The other platforms are haiku and psp. They both have compile-time constants too.


    return 1000000;


    return 1000;

Even the dummy implementation just returns 1000. Obviously, it won’t be of any use there if the counter functions throw SDL_Unsupported.