0.c++-打印函数时间

 自己随手写的,方便测试绘制代码用。
class CFunTime
{
public:
    CFunTime()
	{
		TimeStart=GetTickCount();
	}
	~CFunTime()
	{
        TimeEnd=GetTickCount();
		TRACE("time:%d\n", TimeEnd-TimeStart);
	}

private:
	DWORD TimeStart;
	DWORD TimeEnd;
};

这个函数只精确到55ms,1个tick就是55ms。

第二种:

class CFunTime
{
public:
    CFunTime()
 {
  QueryPerformanceCounter(&TimeStart);
 }
 ~CFunTime()
 {
       QueryPerformanceCounter(&TimeEnd);
  TRACE("time:%d\n", TimeEnd.QuadPart-TimeStart.QuadPart);
 }

private:
 LARGE_INTEGER TimeStart;
 LARGE_INTEGER TimeEnd;
};


第三种方法:

#include "Mmsystem.h"
#pragma comment(lib, "Winmm.lib")
class CFunTime
{
public:
    CFunTime()
	{
		TimeStart = timeGetTime();
	}
	~CFunTime()
	{
		TimeEnd = timeGetTime();
		TRACE("time:%d\n", TimeEnd-TimeStart);
	}

private:
	DWORD TimeStart;
	DWORD TimeEnd;
};

timeGetTime()基本等于GetTickCount(),但是精度更高

 

第四种方法:

#pragma warning(disable : 4035)

inline unsigned __int64 GetCycleCount(void)
{
	_asm    _emit 0x0F
	_asm    _emit 0x31
}

class KTimer
{
	unsigned __int64  m_startcycle;

public:

	unsigned __int64  m_overhead;

	KTimer(void)
	{
		m_overhead = 0;
		Start();
		m_overhead = Stop();
	}

	void Start(void)
	{
		m_startcycle = GetCycleCount();
	}

	unsigned __int64 Stop(void)
	{
		return GetCycleCount()-m_startcycle-m_overhead;
	}
};


windows图形编程第15

你可能感兴趣的:(0.c++-打印函数时间)