The SDL forums have moved to
This is just a read-only archive of the previous forums, to keep old links working.

SDL Forum Index
Simple Directmedia Layer Forums
High resolution timing functions (windows testing needed)
Sam Lantinga

Joined: 10 Sep 2009
Posts: 1765
I recently added a high resolution timing API for profiling and other sub-millisecond timing:
Uint64 SDL_GetPerformanceCounter();
Uint64 SDL_GetPerformanceFrequency()

On Windows these are based on QueryPerformanceCounter() and QueryPerformanceFrequency(), which traditionally have problems.

I'd like to get detailed feedback on what platforms people have encountered problems with these APIs, and strategies for dealing with them.  I'm familiar with a lot of the issues that pre-date Windows XP, but I'm curious what issues are current and on what systems.  Please don't just google for this, I'm interested in your actual current experience.
You can check these out in the latest snapshot here:

    -Sam Lantinga, Founder and CEO, Galaxy Gameworks
High resolution timing functions (windows testing needed)
Forest Hale

I'd like to highlight the aspects of these functions that are likely to vary across different hardware setups and power management modes:

1. QueryPerformanceFrequency might change (rapidly) due to dynamic cpu clocking (laptops and desktops both do this to save power).

2. QueryPerformanceCounter and QueryPerformanceFrequency might change due to independent core timers (from the earliest AMD Athlon 64 X2 processors this issue appeared, and affected at least Mozilla
Thunderbird network timeouts when it used these functions).

I am not sure how stable these issues are in different Windows versions, so I am equally interested in the results for my own curiosity...

I have confidence in these functions for timing within a single game frame at least - check the frequency and store the current counter value, then at each stage of game processing you save off the
current counter value, then at the end you print a report of the timing for this frame.

What is more of an open question is their usefulness over longer timescales... In any case they are a welcome addition for performance analysis.

Author of DarkPlaces Quake1 engine -
Co-designer of Nexuiz -
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

SDL mailing list