Changeset 477 for library/tests/unittest-cpp/Win32
- Timestamp:
- 08/05/09 14:40:03 (15 years ago)
- Location:
- library/tests/unittest-cpp/Win32
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/unittest-cpp/Win32/TimeHelpers.cpp
r418 r477 5 5 6 6 Timer::Timer() 7 : m_threadHandle(::GetCurrentThread()) 8 , m_startTime(0) 9 { 7 : m_threadHandle ( ::GetCurrentThread() ) 8 , m_startTime ( 0 ) { 10 9 #if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR? 11 10 typedef unsigned long DWORD_PTR; … … 13 12 14 13 DWORD_PTR systemMask; 15 ::GetProcessAffinityMask (GetCurrentProcess(), &m_processAffinityMask, &systemMask);16 ::SetThreadAffinityMask (m_threadHandle, 1);17 ::QueryPerformanceFrequency (reinterpret_cast< LARGE_INTEGER* >(&m_frequency));18 ::SetThreadAffinityMask (m_threadHandle, m_processAffinityMask);14 ::GetProcessAffinityMask ( GetCurrentProcess(), &m_processAffinityMask, &systemMask ); 15 ::SetThreadAffinityMask ( m_threadHandle, 1 ); 16 ::QueryPerformanceFrequency ( reinterpret_cast< LARGE_INTEGER* > ( &m_frequency ) ); 17 ::SetThreadAffinityMask ( m_threadHandle, m_processAffinityMask ); 19 18 } 20 19 21 void Timer::Start() 22 { 20 void Timer::Start() { 23 21 m_startTime = GetTime(); 24 22 } 25 23 26 double Timer::GetTimeInMs() const 27 { 24 double Timer::GetTimeInMs() const { 28 25 __int64 const elapsedTime = GetTime() - m_startTime; 29 double const seconds = double (elapsedTime) / double(m_frequency);26 double const seconds = double ( elapsedTime ) / double ( m_frequency ); 30 27 return seconds * 1000.0; 31 28 } 32 29 33 __int64 Timer::GetTime() const 34 { 30 __int64 Timer::GetTime() const { 35 31 LARGE_INTEGER curTime; 36 ::SetThreadAffinityMask (m_threadHandle, 1);37 ::QueryPerformanceCounter (&curTime);38 ::SetThreadAffinityMask (m_threadHandle, m_processAffinityMask);32 ::SetThreadAffinityMask ( m_threadHandle, 1 ); 33 ::QueryPerformanceCounter ( &curTime ); 34 ::SetThreadAffinityMask ( m_threadHandle, m_processAffinityMask ); 39 35 return curTime.QuadPart; 40 36 } 41 37 42 void TimeHelpers::SleepMs(int const ms) 43 { 44 ::Sleep(ms); 38 void TimeHelpers::SleepMs ( int const ms ) { 39 ::Sleep ( ms ); 45 40 } 46 41 -
library/tests/unittest-cpp/Win32/TimeHelpers.h
r418 r477 6 6 7 7 #ifdef UNITTEST_MINGW 8 9 10 8 #ifndef __int64 9 #define __int64 long long 10 #endif 11 11 #endif 12 12 13 13 namespace UnitTest { 14 14 15 class Timer 16 { 15 class Timer { 17 16 public: 18 17 Timer(); 19 18 void Start(); 20 double GetTimeInMs() const; 19 double GetTimeInMs() const; 21 20 22 21 private: 23 22 __int64 GetTime() const; 24 23 25 24 void* m_threadHandle; 26 25 27 26 #if defined(_WIN64) 28 27 unsigned __int64 m_processAffinityMask; 29 28 #else 30 29 unsigned long m_processAffinityMask; 31 30 #endif 32 31 … … 36 35 37 36 38 namespace TimeHelpers 39 { 40 void SleepMs (int ms); 37 namespace TimeHelpers { 38 void SleepMs ( int ms ); 41 39 } 42 40