elapsed.cpp

来自「CPU 多媒体指令(MMX、SSE等)应用实例」· C++ 代码 · 共 63 行

CPP
63
字号
// Elapsed.cpp: implementation of the CElapsed class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Elapsed.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CElapsed::CElapsed()
{
	// get the frequency of the counter
	m_iInitialized = QueryPerformanceFrequency( (LARGE_INTEGER *)&m_iFrequency );
}

CElapsed::~CElapsed()
{

}

BOOL CElapsed::Begin()    // start timing
{
	if (!m_iInitialized)
		return 0;   // error - couldn't get frequency

	// get the starting counter value
	return QueryPerformanceCounter( (LARGE_INTEGER *)&m_iBeginTime );
}

double CElapsed::End()    // stop timing and get elapsed time in seconds
{
	if (!m_iInitialized )
		return 0.0; // error - couldn't get frequency

	// get the ending counter value
	__int64 endtime;
	QueryPerformanceCounter( (LARGE_INTEGER *)&endtime );

	// determine the elapsed counts
	__int64 elapsed = endtime - m_iBeginTime;

	// convert counts to time in seconds and return it
	m_dElapsed = (double)elapsed / (double)m_iFrequency;
	return m_dElapsed;
}

BOOL CElapsed::Available()  // returns true if the perf counter is available
{ 
	return m_iInitialized; 
}

__int64 CElapsed::GetFreq() // return perf counter frequency as large int
{
	return m_iFrequency; 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?