Monday, December 14, 2009

Windows Win32 Timer or Time Counting

If you want to make a timer that only depends on the kernel, GetTickCount64 is an easy way to do it.


http://msdn.microsoft.com/en-us/library/ms724411%28VS.85%29.aspx


The code is simple and would look like this:


ULONGLONG Ticks = 0;

Ticks = GetTickCount64();

//
// some code to time
//

Ticks = GetTickCount64() - Ticks;


Note: GetTickCount64 returns the number of ms since the system was last booted. Theoretically you might have check for wrapping of the clock; however, 2^64 ms or ~49.7 days is a long time. If you are worried about that, you might consider other APIs that keep track of the full time with a ms resolution.

No comments:

Post a Comment