bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 1 | #include "BenchSysTimer_windows.h" |
| 2 | |
| 3 | //Time |
| 4 | #define WIN32_LEAN_AND_MEAN 1 |
| 5 | #include <Windows.h> |
| 6 | |
| 7 | static ULONGLONG winCpuTime() { |
| 8 | FILETIME createTime; |
| 9 | FILETIME exitTime; |
| 10 | FILETIME usrTime; |
| 11 | FILETIME sysTime; |
| 12 | if (0 == GetProcessTimes(GetCurrentProcess() |
| 13 | , &createTime, &exitTime |
| 14 | , &sysTime, &usrTime)) |
| 15 | { |
| 16 | return 0; |
| 17 | } |
| 18 | ULARGE_INTEGER start_cpu_sys; |
| 19 | ULARGE_INTEGER start_cpu_usr; |
| 20 | start_cpu_sys.LowPart = sysTime.dwLowDateTime; |
| 21 | start_cpu_sys.HighPart = sysTime.dwHighDateTime; |
| 22 | start_cpu_usr.LowPart = usrTime.dwLowDateTime; |
| 23 | start_cpu_usr.HighPart = usrTime.dwHighDateTime; |
| 24 | return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart; |
| 25 | } |
| 26 | |
| 27 | void BenchSysTimer::startWall() { |
| 28 | if (0 == ::QueryPerformanceCounter(&this->fStartWall)) { |
| 29 | this->fStartWall.QuadPart = 0; |
| 30 | } |
| 31 | } |
| 32 | void BenchSysTimer::startCpu() { |
| 33 | this->fStartCpu = winCpuTime(); |
| 34 | } |
| 35 | |
| 36 | double BenchSysTimer::endCpu() { |
| 37 | ULONGLONG end_cpu = winCpuTime(); |
| 38 | return (end_cpu - this->fStartCpu) / 10000; |
| 39 | } |
| 40 | double BenchSysTimer::endWall() { |
| 41 | LARGE_INTEGER end_wall; |
| 42 | if (0 == ::QueryPerformanceCounter(&end_wall)) { |
| 43 | end_wall.QuadPart = 0; |
| 44 | } |
| 45 | |
| 46 | LARGE_INTEGER ticks_elapsed; |
| 47 | ticks_elapsed.QuadPart = end_wall.QuadPart - this->fStartWall.QuadPart; |
| 48 | |
| 49 | LARGE_INTEGER frequency; |
| 50 | if (0 == ::QueryPerformanceFrequency(&frequency)) { |
| 51 | return 0; |
| 52 | } else { |
| 53 | return (double)ticks_elapsed.QuadPart / frequency.QuadPart * 1000; |
| 54 | } |
| 55 | } |