blob: 923754c264390bb3003da2b631ea3e6fe8a2e572 [file] [log] [blame]
bungeman@google.combe9ad4e2011-06-07 19:16:02 +00001#include "BenchSysTimer_windows.h"
2
3//Time
4#define WIN32_LEAN_AND_MEAN 1
5#include <Windows.h>
6
7static 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
27void BenchSysTimer::startWall() {
28 if (0 == ::QueryPerformanceCounter(&this->fStartWall)) {
29 this->fStartWall.QuadPart = 0;
30 }
31}
32void BenchSysTimer::startCpu() {
33 this->fStartCpu = winCpuTime();
34}
35
36double BenchSysTimer::endCpu() {
37 ULONGLONG end_cpu = winCpuTime();
38 return (end_cpu - this->fStartCpu) / 10000;
39}
40double 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}