//ElapsedTime.h
#ifndef _ELAPSED
#define _ELAPSED
class CElapsed
{
private:
int Initialized;
_int64 Frequency;
_int64 BeginTime;
public:
CElapsed();
bool Begin();
double End(); //停止计数
bool Available();//是否可调用这两个函数
_int64 GetFreq();
};
#endif
//ElapsedTime.cpp
//另外gettickcount()这个函数也是可以精确到ms的
#include <stdafx.h>
#include "ElapsedTime.h"
CElapsed::CElapsed()
{
Initialized=QueryPerformanceFrequency((LARGE_INTEGER *)&Frequency);
}
bool CElapsed:: Begin()
{
if(!Initialized)
return 0; //某些CPU不运行此函数调用
return QueryPerformanceCounter((LARGE_INTEGER *)&BeginTime);
}
double CElapsed::End() //停止计数
{
if(!Initialized)
return 0.0; //某些CPU不运行此函数调用
_int64 endtime;
QueryPerformanceCounter((LARGE_INTEGER *)&endtime);
_int64 elapsed=endtime-BeginTime;
return (double)elapsed/(double)Frequency;
}
bool CElapsed::Available()//是否可调用这两个函数
{
return Initialized;
}
_int64 CElapsed::GetFreq()
{
return Frequency;
}
本文地址:http://com.8s8s.com/it/it762.htm