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