blob: 1c4e4049c8a164f7ef4e9099365844561173b3ea [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
bungeman@google.combe9ad4e2011-06-07 19:16:02 +00008#include "BenchSysTimer_windows.h"
9
10//Time
11#define WIN32_LEAN_AND_MEAN 1
12#include <Windows.h>
13
14static 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
34void BenchSysTimer::startWall() {
35 if (0 == ::QueryPerformanceCounter(&this->fStartWall)) {
36 this->fStartWall.QuadPart = 0;
37 }
38}
39void BenchSysTimer::startCpu() {
40 this->fStartCpu = winCpuTime();
41}
42
43double BenchSysTimer::endCpu() {
44 ULONGLONG end_cpu = winCpuTime();
bungeman@google.coma38c8192011-10-03 20:44:39 +000045 return static_cast<double>((end_cpu - this->fStartCpu)) / 10000.0L;
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000046}
47double BenchSysTimer::endWall() {
48 LARGE_INTEGER end_wall;
49 if (0 == ::QueryPerformanceCounter(&end_wall)) {
50 end_wall.QuadPart = 0;
51 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000052
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000053 LARGE_INTEGER ticks_elapsed;
54 ticks_elapsed.QuadPart = end_wall.QuadPart - this->fStartWall.QuadPart;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000056 LARGE_INTEGER frequency;
57 if (0 == ::QueryPerformanceFrequency(&frequency)) {
bungeman@google.coma38c8192011-10-03 20:44:39 +000058 return 0.0L;
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000059 } else {
bungeman@google.coma38c8192011-10-03 20:44:39 +000060 return static_cast<double>(ticks_elapsed.QuadPart)
bungeman@google.comc9614422011-10-19 22:10:21 +000061 / static_cast<double>(frequency.QuadPart)
62 * 1000.0L;
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000063 }
64}