|
Revision 418, 1.1 kB
(checked in by vbarta, 16 years ago)
|
|
#27: added UnitTest?++ to bdm sources, changed test_user_data to use it
|
| 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 | { |
|---|
| 10 | #if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR? |
|---|
| 11 | typedef unsigned long DWORD_PTR; |
|---|
| 12 | #endif |
|---|
| 13 | |
|---|
| 14 | 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); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | void Timer::Start() |
|---|
| 22 | { |
|---|
| 23 | m_startTime = GetTime(); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | double Timer::GetTimeInMs() const |
|---|
| 27 | { |
|---|
| 28 | __int64 const elapsedTime = GetTime() - m_startTime; |
|---|
| 29 | double const seconds = double(elapsedTime) / double(m_frequency); |
|---|
| 30 | return seconds * 1000.0; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | __int64 Timer::GetTime() const |
|---|
| 34 | { |
|---|
| 35 | LARGE_INTEGER curTime; |
|---|
| 36 | ::SetThreadAffinityMask(m_threadHandle, 1); |
|---|
| 37 | ::QueryPerformanceCounter(&curTime); |
|---|
| 38 | ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); |
|---|
| 39 | return curTime.QuadPart; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | void TimeHelpers::SleepMs(int const ms) |
|---|
| 43 | { |
|---|
| 44 | ::Sleep(ms); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | } |
|---|