Archived

This topic is now archived and is closed to further replies.

Austrian Coder

RDTSCTimer

Recommended Posts

Hi! I am working on a little timer and i want to use RDTSC, if possible. This i call when i want to reset the timer:
  
__int64 m_cycles;

m_cycles = GetRdtscCycleCount();

inline __int64 CTimer::GetRdtscCycleCount()
{ 
	unsigned int dwLow, dwHigh;
	__asm 
	{
		cpuid
		RDTSC
		mov dwLow, eax
		mov dwHigh, edx
	}

	return (((__int64) dwHigh) << 32) | ((__int64) dwLow);
}
  
And if i want to get the passed ms i do this:
  
float CTimer::GetPassedMs()
{
	...
	m_cycles -= GetRdtscCycleCount();
	return (m_cycles/m_cpufreqenz) * 1000.0f;
	...
}
  
The problem is that i get very high values when calling GetPassedMs(). So where is my mistake? Thanks, Christian

Share this post


Link to post
Share on other sites
Change:
m_cycles -= GetRdtscCycleCount();
to this:
m_cycles = GetRdtscCycleCount() - m_cycles;

shold help

Share this post


Link to post
Share on other sites