Archived

This topic is now archived and is closed to further replies.

sporadic QueryPerformanceCounter

This topic is 5825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some odd reason queryperformancecounter() is diverging from the clock(). The counter / frequency - starttime should yield the same value for both. When the app is run in debug mode with frequent break points, the timers remain in sync. However when left alone for a long interval the queryperformancecounter time grows exponentially. I am at the end of my wits as to what would cause this. Please help.

Share this post


Link to post
Share on other sites
Well, the clock() is only accurate to about 50-60ms on most systems. THe QueryPerformanceCounter is accurate to several nanoseconds, not sure about the exact number. It uses __int64 and such, so yes, it will diverge slowly from clock().

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites
It diverges too quickly to be that. Besides, although they have differing resolutions, both should be approximately the same after a given number of seconds (+-50ms). For some odd reason the queryperformancecounter says 20 seconds after about 5.

Share this post


Link to post
Share on other sites
Are you sure the system takes high-frequency times properly? And the calculations for the time are also correct?

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Instead of calling QueryPerformanceCounter, call the RDTSC command directly. You will get a 1:1 result directly from the hardware timestamp counter of the CPU. If it still doesn''t work, then it''s your code.

Share this post


Link to post
Share on other sites
QueryPerformanceCounter() may sometimes fail in interesting ways:

http://www.etestinglabs.com/bi/cont2000/200012/perfcnt.asp
http://support.microsoft.com/support/kb/articles/Q274/3/23.ASP

Let me know if either of these explains your problem, as I'm interested in finding out just how rare these bugs are.


Edited by - fprefect on January 3, 2002 1:34:18 PM

Share this post


Link to post
Share on other sites
Thank you fprefect, that was exactly my problem. I don''t think the problem is very prevalent, as it only happens in certain instances on a few chipsets (just enough to make the programmer go crazy with unexplainable problems). Microsoft''s answer was lame (not out fault, flaw is by design), and it said to check the counter against the clock() and correct as necessary. I think I will use rtdsc, though I''m having problems measuring the cycles per second accurately enough for long term timing.

Share this post


Link to post
Share on other sites