Archived

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

QueryPerformanceCounter...

This topic is 5649 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

Two questions about this. I''m currently using GetTickCount () to time frame draw times (for time-scaling), and it is working pretty well, but I''d be interested in switching to a more accurate system. QueryPerformanceCounter and QueryPerformanceFrequency both state that they will work if a "high resolution timer" is available. Am I limiting my audience by using these? Do any Pentium class computers not have a high resolution timer? Secondly, can someone give me an example of how I''d use the LARGE_INTEGERS returned? I''m a bit sketchy on the best way to find the difference between two LARGE_INTEGER values and then use the frequency to work out the time. Theoretically it should just be: Difference (counts) / Frequency (counts / seconds) = time seconds but I''m not sure how I''d accomplish this with large integers... can anyone give me an example? Thanks in advance.

Share this post


Link to post
Share on other sites
This is what I use. (until I find bugs in it

  
static __int64 Rate;
static __int64 Count;
static u32 UseWinMM=0;
//-----------------------------------------------------------------------------

// Name: Time_Init()

// Desc: Inits time system

//-----------------------------------------------------------------------------

void Time_Init(void)
{


UseWinMM = 0;

if(!QueryPerformanceFrequency( (LARGE_INTEGER*)&Rate ) )
UseWinMM =1;

if(!QueryPerformanceCounter( (LARGE_INTEGER*)&Count ) )
UseWinMM = 1;

if( UseWinMM )
{
//____________________________________________________________________

// setup platform timer

TIMECAPS tc;
if( timeGetDevCaps(&tc, sizeof( TIMECAPS ) ) == TIMERR_NOERROR )
{
// set min tick period {accuracy of timer} to 1

DWORD TimerRes = min( max( tc.wPeriodMin, 1 ), tc.wPeriodMax );
timeBeginPeriod( TimerRes );

}
}
}

//-----------------------------------------------------------------------------

// Name: Time_Get()

// Desc: returns Time in seconds, 0.5 == half second

//-----------------------------------------------------------------------------

inline f32 Time_Get(void)
{
if( UseWinMM )
return(timeGetTime()/1000.f);
else
{
QueryPerformanceCounter( (LARGE_INTEGER*)&Count );
return((f32)Count / (f32)Rate);
}
}




If there isnt a performance timer I use the multimedia one instead.

Share this post


Link to post
Share on other sites
If it goes wrong, check your motherboard with a list on MSDN (I can never remember the page). The performance counter isn''t reliable with some boards, it jumps several seconds occasionly.

,Jay

Share this post


Link to post
Share on other sites