Revision 706, 1.1 kB
(checked in by smidl, 15 years ago)
|
eol-native
|
-
Property svn:eol-style set to
native
|
Line | |
---|
1 | #include "TimeHelpers.h" |
---|
2 | #include <windows.h> |
---|
3 | |
---|
4 | namespace UnitTest { |
---|
5 | |
---|
6 | Timer::Timer() |
---|
7 | : m_threadHandle ( ::GetCurrentThread() ) |
---|
8 | , m_startTime ( 0 ) { |
---|
9 | #if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR? |
---|
10 | typedef unsigned long DWORD_PTR; |
---|
11 | #endif |
---|
12 | |
---|
13 | DWORD_PTR systemMask; |
---|
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 ); |
---|
18 | } |
---|
19 | |
---|
20 | void Timer::Start() { |
---|
21 | m_startTime = GetTime(); |
---|
22 | } |
---|
23 | |
---|
24 | double Timer::GetTimeInMs() const { |
---|
25 | __int64 const elapsedTime = GetTime() - m_startTime; |
---|
26 | double const seconds = double ( elapsedTime ) / double ( m_frequency ); |
---|
27 | return seconds * 1000.0; |
---|
28 | } |
---|
29 | |
---|
30 | __int64 Timer::GetTime() const { |
---|
31 | LARGE_INTEGER curTime; |
---|
32 | ::SetThreadAffinityMask ( m_threadHandle, 1 ); |
---|
33 | ::QueryPerformanceCounter ( &curTime ); |
---|
34 | ::SetThreadAffinityMask ( m_threadHandle, m_processAffinityMask ); |
---|
35 | return curTime.QuadPart; |
---|
36 | } |
---|
37 | |
---|
38 | void TimeHelpers::SleepMs ( int const ms ) { |
---|
39 | ::Sleep ( ms ); |
---|
40 | } |
---|
41 | |
---|
42 | } |
---|