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