0.c++-関数の印刷時間

1567 ワード

自分で勝手に書いたので、コードをテストするのに便利です.
class CFunTime
{
public:
    CFunTime()
	{
		TimeStart=GetTickCount();
	}
	~CFunTime()
	{
        TimeEnd=GetTickCount();
		TRACE("time:%d
", TimeEnd-TimeStart); } private: DWORD TimeStart; DWORD TimeEnd; };

この関数は55 msまで正確で,1つのtickは55 msである.
2つ目:
class CFunTime
{
public:
    CFunTime()
 {
  QueryPerformanceCounter(&TimeStart);
 }
 ~CFunTime()
 {
       QueryPerformanceCounter(&TimeEnd);
  TRACE("time:%d
", TimeEnd.QuadPart-TimeStart.QuadPart); } private: LARGE_INTEGER TimeStart; LARGE_INTEGER TimeEnd; };

3つ目の方法:
#include "Mmsystem.h"
#pragma comment(lib, "Winmm.lib")
class CFunTime
{
public:
    CFunTime()
	{
		TimeStart = timeGetTime();
	}
	~CFunTime()
	{
		TimeEnd = timeGetTime();
		TRACE("time:%d
", TimeEnd-TimeStart); } private: DWORD TimeStart; DWORD TimeEnd; };

timeGetTime()はGetTickCount()にほぼ等しいが、より精度が高い
 
4つ目の方法:
#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