Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » time measurement :: RTIMING, TimeStop, GetTickCount
Re: time measurement :: RTIMING, TimeStop, GetTickCount [message #36186 is a reply to message #36185] Wed, 09 May 2012 15:26 Go to previous messageGo to previous message
cbpporter is currently offline  cbpporter
Messages: 1428
Registered: September 2007
Ultimate Contributor
The real problem with GetTickCount is the resolution. I find it way too low for most practical purposes, because two close measurements will almost always return 0, 15 or 16 ms.

I don't have a proper solution at hand right now, but this should work fairly well:
class HRTimer {
private:
    LARGE_INTEGER start;

    LARGE_INTEGER stop;

    double frequency;
   
public:
    HRTimer() {
        frequency = GetFrequency();
    }
   
    double GetFrequency();
    void StartTimer();
    double StopTimer();
};

double HRTimer::GetFrequency(void) {
    LARGE_INTEGER proc_freq;

    if (!::QueryPerformanceFrequency(&proc_freq)) {
        ASSERT(0);
    }

    return proc_freq.QuadPart;
}

void HRTimer::StartTimer(void) {
    DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);

    ::QueryPerformanceCounter(&start);

    ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
}

double HRTimer::StopTimer(void) {
    DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);

    ::QueryPerformanceCounter(&stop);

    ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);

    return ((stop.QuadPart - start.QuadPart) / frequency);
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Search for constant and show it....
Next Topic: How do I 'check' a Switch control
Goto Forum:
  


Current Time: Sun Aug 24 20:34:17 CEST 2025

Total time taken to generate the page: 0.00590 seconds