一个精度很高的计时器

来源:互联网 发布:传奇怪物数据论坛 编辑:程序博客网 时间:2024/05/01 04:50
//---------------------------------------------------------------------------
// get the millseconds from the demo start - time line
//---------------------------------------------------------------------------
float GetTime()
{
  
static bool init = false;
  
static bool hires = false;
  
static __int64 freq = 1;
  
if(!init)
  
{
    hires 
= !QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
    
if(!hires)
      freq 
= 1000;
    init 
= true;
  }


  __int64 now;

  
if(hires)
    QueryPerformanceCounter((LARGE_INTEGER 
*)&now);
  
else
    now 
= GetTickCount();

  
return (float)((double)now / (double)freq);
}