Home » Source Code » » PreciseTimer.h

PreciseTimer.h ( File view )

From:
  • By 2010-08-24
  • View(s):3
  • Download(s):0
  • Point(s): 1
			
//PreciseTimer.h

#ifndef _PRECISETIMER_H_
#define _PRECISE_H_

//More precise Timer for measuring time intervals in microseconds.
//The performance of this Timer is dependent on the performance of the system.
class CPreciseTimer
{

public:
	//CONSTRUCTOR
	CPreciseTimer();

	bool SupportsHighResCounter();
	void StartTimer();
	void StopTimer();
	__int64 GetTime();

private:
	//Auxiliary Function
	void UpdateElapsed();

	//Member variables
	bool m_bRunning;	
	__int64 m_i64Start;
	__int64 m_i64Elapsed;

	//Some auxiliary variables
	__int64 m_i64Counts;
	LARGE_INTEGER m_liCount;

	//Static Variables
	static bool sm_bInit;
	static bool sm_bPerformanceCounter;
	static __int64 sm_i64Freq;

};

inline bool CPreciseTimer::SupportsHighResCounter()
{

	return sm_bPerformanceCounter;

}

//Auxiliary Function
inline void CPreciseTimer::UpdateElapsed()
{

	if(true == sm_bPerformanceCounter)
	{

		QueryPerformanceCounter(&m_liCount);
		m_i64Counts = ((__int64)m_liCount.HighPart << 32) + (__int64)m_liCount.LowPart;
		//Transform in microseconds
		(m_i64Counts *= 1000000) /= sm_i64Freq;
	
}
	else
		//Transform milliseconds to microseconds
		m_i64Counts = (__int64)GetTickCount() * 1000;
	if(m_i64Counts > m_i64Start)
		m_i64Elapsed = m_i64Counts - m_i64Start;
	else
		//Eliminate possible number overflow (0x7fffffffffffffff is the maximal __int64 positive number)
		m_i64Elapsed = (0x7fffffffffffffff - m_i64Start) + m_i64Counts;

}

#endif // _PRECISETIMER_H_


			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
PreciseTimer.cpp1.32 kB10-11-01 14:48
PreciseTimer.dsp4.50 kB10-11-01 14:56
PreciseTimer.dsw547.00 B10-11-01 14:34
PreciseTimer.h1.49 kB10-12-01 09:44
StdAfx.cpp294.00 B02-05-01 12:34
StdAfx.h693.00 B10-11-01 14:48
Test.cpp1.25 kB10-12-01 09:48
...
Sponsored links

PreciseTimer.h (4.59 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D