Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

High performance computing from C++ to MMX

, 30 Jul 2003
Boosting you application performance to the optimum by using hardware acceleration.
// 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; 
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Vincent Leong77
Web Developer Cortex Imaging
Malaysia Malaysia
Interest in computer vision, biometrics, image processing & software optimizations. Known language C/C++, VC++ MFC, Win32, COM/ATL, Assembly.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 31 Jul 2003
Article Copyright 2003 by Vincent Leong77
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid