Home » Source Code » » PreciseTimer.cpp

PreciseTimer.cpp ( File view )

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

#include "stdafx.h"
#include "PreciseTimer.h"

bool CPreciseTimer::sm_bInit = false;
bool CPreciseTimer::sm_bPerformanceCounter;
__int64 CPreciseTimer::sm_i64Freq;

//CONSTRUCTOR
CPreciseTimer::CPreciseTimer() : m_i64Start(0), m_i64Elapsed(0), m_bRunning(false)
{

	//Only if not already initialized
	if(false == sm_bInit)
	{

		//Initializing some static variables dependent on the system just once
		LARGE_INTEGER liFreq;
		if(TRUE == QueryPerformanceFrequency(&liFreq))
		{

			//Only if the system is supporting High Performance
			sm_i64Freq = ((__int64)liFreq.HighPart << 32) + (__int64)liFreq.LowPart;
			sm_bPerformanceCounter = true;
		
}
		else
			sm_bPerformanceCounter = false;
		sm_bInit = true;
	
}

}

void CPreciseTimer::StartTimer()
{

	if(true == sm_bPerformanceCounter)
	{

		QueryPerformanceCounter(&m_liCount);
		m_i64Start = ((__int64)m_liCount.HighPart << 32) + (__int64)m_liCount.LowPart;
		//Transform in microseconds
		(m_i64Start *= 1000000) /= sm_i64Freq;
	
}
	else
		//Transform milliseconds to microseconds
		m_i64Start = (__int64)GetTickCount() * 1000;
	m_bRunning = true;

}

void CPreciseTimer::StopTimer()
{

	UpdateElapsed();
	m_bRunning = false;

}

__int64 CPreciseTimer::GetTime()
{

	if(true == m_bRunning)
		UpdateElapsed();
	return m_i64Elapsed;

}

			
...
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.cpp (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