What is the most accurate, best get time function? I used to use GetTickCount(), but it is incredibly inaccurate, and timeGetTime() is just as bad. Any suggestions?
-Vulcan
What is the most accurate, best get time function? I used to use GetTickCount(), but it is incredibly inaccurate, and timeGetTime() is just as bad. Any suggestions?
-Vulcan
Here are the functions from Dhonn's hi-res timer:
// Global variables
// frametime will return the time between frames
// 1.0 / frametime will give the fps
double rate_inv, startclock, start_time, end_time, frametime;
// Initialise hi-res timer
bool initftime(void)
{
__int64 rate;
// we need the accuracy
if(!QueryPerformanceFrequency((LARGE_INTEGER*)&rat e))
{
return FALSE; // win errors
}
// usually the rate will be 1193180
if(!rate)
{
return FALSE;
}
rate_inv=1.0/(double)rate;
if(!QueryPerformanceCounter((LARGE_INTEGER*)&start clock))
{
return FALSE; // win errors
}
return TRUE; // there is a clock
}
double ftime(void)
{
// by dividing by its rate you get accurate seconds
__int64 endclock;
QueryPerformanceCounter((LARGE_INTEGER*)&endclock) ;
return (double)(endclock-startclock)*rate_inv;
// note: I recommend that you multiply but the inverse of a constant.
// (speed reasons)
}
// Returns the time between frames (assuming this function is
// called every frame.
void GetFrameTime(void)
{
do
{
start_time = ftime();
} while(start_time==end_time);
// the total time it took to put together the last frame
// and get back here...
frametime = start_time - end_time;
end_time = start_time;
}
It works great most of the time, but I've had problems with it being choppy in XP.
I use timeGetTime() for everything, just remember it returns the number of miliseconds since the machine was started in an integer number.