高精度定时器

#ifndef CAL_TIME_INC_
#define CAL_TIME_INC_

#include <windows.h>

class CalTime {
public:
	CalTime();
	~CalTime();
	void Start();
	void Stop();
	float GetCalTime();
private:
	LARGE_INTEGER freq;
	LARGE_INTEGER start;
	LARGE_INTEGER stop;
};

#endif // CalTime.h
//
//	name: CalTime 
//	author: yangj
//	time: 2011-04-07
// 

#include "stdafx.h"
#include "CalTime.h"

CalTime::CalTime()
{
	if (!::QueryPerformanceFrequency(&freq)) {
		printf("Cannot support QueryTime\n");
	}
}

CalTime::~CalTime()
{}

void CalTime::Start()
{
	::QueryPerformanceCounter(&start);
}

void CalTime::Stop()
{
	::QueryPerformanceCounter(&stop);
}

float CalTime::GetCalTime()
{
	float val = stop.QuadPart - start.QuadPart;
	return (val / (float)(freq.QuadPart));
}

你可能感兴趣的:(高精度定时器)