timeGetTime or QueryPerformanceCounter

Started by
3 comments, last by popsoftheyear 15 years, 4 months ago
Hello, I need to design a timer to work with multiple threads. I have used timeGetTime before and worked well with no parallel programming. What i don't know is what works best for multiple threads and what are the implication of different CPU architecture (amd / intel) , will this affect the timers? For the start all i want is for each background thread to have a timer and the threads do not have affinity for the CPU. thanks.
Advertisement
Both should be fine I believe. RDTSC is the method you shouldn't use!
Cheers,MartinIf I've helped you, a rating++ would be appreciated
Quote:Original post by Martin
Both should be fine I believe. RDTSC is the method you shouldn't use!
QPC() has some issues on older CPUs actually, and on some systems it's implemented as a RDTSC call - which means it'll break horribly on multiple processors / cores.

I'd suggest just sticking with timeGetTime(), unless you need timing more accurate than ~1ms.
QueryPerformanceTimer() uses RTDSC on a widely available Windows version, and it uses it badly. On new hardware under Vista, there is no such issue, but you hardly have a way of knowing, unless you write "minimum requirement: Vista" on the package. In other words, the function isn't reliable.

timeGetTime() is ok, but has a much lower resolution. If that is acceptable, then timeGetTime() is the one you want to use.

RTDSC works fine on one CPU core, but otherwise shows random negative time step effects. I'm using RTDSC in a separate thread that binds to CPU0 and updates the tick counter at request when a semaphore is posted. That sounds terrible, but it's (surprisingly) quite fast, and for all I can tell, it works 100% reliably.
Microsoft recommends QPC:

http://msdn.microsoft.com/en-us/library/bb173458(VS.85).aspx
-- gekko
Quote:Original post by gekko
Microsoft recommends QPC:

http://msdn.microsoft.com/en-us/library/bb173458(VS.85).aspx


That article suggests QPC because of flaws in RTDSC, but yet it was just noted that some versions of XP have QPC implemented using RTDSC...

I personally use timeGetTime. It too has its own problems (not counting the 1ms resolution "issue"), but of the limited choices at your disposal, it seems to be the least of evils.

Search around here for older threads on this topic, and you'll find an abundance of information.

Cheers
-Scott

[edit] I'd be really curious as to if anyone has any insight to potential problems with samoth's method.

This topic is closed to new replies.

Advertisement