65,186
社区成员




#ifndef _GETTIME_H_
#define _GETTIME_H_
// Using WINDOWS API get the High-precision time.
#include <math.h>
#define GT_S 0 // second
#define GT_MS 1 // millisecond
#define GT_US 2 // microsecond
#define GT_NS 3 // nanosecond
class GetTime
{
public:
void start( void )
{
QueryPerformanceFrequency(&m_frequency);
QueryPerformanceCounter(&m_start);
}
void end( void )
{
QueryPerformanceCounter(&m_end);
}
double get(int type)
{
return ((double)(m_end.QuadPart - m_start.QuadPart)/(m_frequency.QuadPart))*pow(1000.0,type);
}
private:
LARGE_INTEGER m_start;
LARGE_INTEGER m_end;
LARGE_INTEGER m_frequency;
};
#endif
高精度计算方法,使用方法:
GetTime gt;
gt.start();
// for
gt.end();
gt.get(GT_MS); // GT_S,GT_MS......