?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #include "TimeHelpers.h"
  2.  
  3. #define WIN32_LEAN_AND_MEAN
  4. #include <windows.h>
  5.  
  6. namespace UnitTest {
  7.  
  8.    Timer::Timer()
  9.       : m_threadHandle(::GetCurrentThread())
  10.       , m_startTime(0)
  11.    {
  12. #if defined(UNITTEST_WIN32) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
  13.       typedef unsigned long DWORD_PTR;
  14. #endif
  15.  
  16.       DWORD_PTR systemMask;
  17.       ::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask);
  18.       ::SetThreadAffinityMask(m_threadHandle, 1);
  19.       ::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency));
  20.       ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
  21.    }
  22.  
  23.    void Timer::Start()
  24.    {
  25.       m_startTime = GetTime();
  26.    }
  27.  
  28.    double Timer::GetTimeInMs() const
  29.    {
  30.       __int64 const elapsedTime = GetTime() - m_startTime;
  31.       double const seconds = double(elapsedTime) / double(m_frequency);
  32.       return seconds * 1000.0;
  33.    }
  34.  
  35.    __int64 Timer::GetTime() const
  36.    {
  37.       LARGE_INTEGER curTime;
  38.       ::SetThreadAffinityMask(m_threadHandle, 1);
  39.       ::QueryPerformanceCounter(&curTime);
  40.       ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
  41.       return curTime.QuadPart;
  42.    }
  43.  
  44.    void TimeHelpers::SleepMs(int ms)
  45.    {
  46.       ::Sleep(ms);
  47.    }
  48.  
  49. }
  50.