| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright 2011 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 #include "BenchSysTimer_windows.h" | |
| 9 | |
| 10 //Time | |
| 11 #define WIN32_LEAN_AND_MEAN 1 | |
| 12 #include <windows.h> | |
| 13 | |
| 14 static ULONGLONG winCpuTime() { | |
| 15 FILETIME createTime; | |
| 16 FILETIME exitTime; | |
| 17 FILETIME usrTime; | |
| 18 FILETIME sysTime; | |
| 19 if (0 == GetProcessTimes(GetCurrentProcess() | |
| 20 , &createTime, &exitTime | |
| 21 , &sysTime, &usrTime)) | |
| 22 { | |
| 23 return 0; | |
| 24 } | |
| 25 ULARGE_INTEGER start_cpu_sys; | |
| 26 ULARGE_INTEGER start_cpu_usr; | |
| 27 start_cpu_sys.LowPart = sysTime.dwLowDateTime; | |
| 28 start_cpu_sys.HighPart = sysTime.dwHighDateTime; | |
| 29 start_cpu_usr.LowPart = usrTime.dwLowDateTime; | |
| 30 start_cpu_usr.HighPart = usrTime.dwHighDateTime; | |
| 31 return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart; | |
| 32 } | |
| 33 | |
| 34 void BenchSysTimer::startWall() { | |
| 35 if (0 == ::QueryPerformanceCounter(&this->fStartWall)) { | |
| 36 this->fStartWall.QuadPart = 0; | |
| 37 } | |
| 38 } | |
| 39 void BenchSysTimer::startCpu() { | |
| 40 this->fStartCpu = winCpuTime(); | |
| 41 } | |
| 42 | |
| 43 double BenchSysTimer::endCpu() { | |
| 44 ULONGLONG end_cpu = winCpuTime(); | |
| 45 return static_cast<double>((end_cpu - this->fStartCpu)) / 10000.0L; | |
| 46 } | |
| 47 double BenchSysTimer::endWall() { | |
| 48 LARGE_INTEGER end_wall; | |
| 49 if (0 == ::QueryPerformanceCounter(&end_wall)) { | |
| 50 end_wall.QuadPart = 0; | |
| 51 } | |
| 52 | |
| 53 LARGE_INTEGER ticks_elapsed; | |
| 54 ticks_elapsed.QuadPart = end_wall.QuadPart - this->fStartWall.QuadPart; | |
| 55 | |
| 56 LARGE_INTEGER frequency; | |
| 57 if (0 == ::QueryPerformanceFrequency(&frequency)) { | |
| 58 return 0.0L; | |
| 59 } else { | |
| 60 return static_cast<double>(ticks_elapsed.QuadPart) | |
| 61 / static_cast<double>(frequency.QuadPart) | |
| 62 * 1000.0L; | |
| 63 } | |
| 64 } | |
| OLD | NEW |