| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * 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 |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "SysTimer_windows.h" | 7 #include "SysTimer_windows.h" |
| 8 | 8 |
| 9 #include <intrin.h> | 9 #include <intrin.h> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 double SysTimer::endCpu() { | 32 double SysTimer::endCpu() { |
| 33 ULONGLONG end_cpu = win_cpu_time(); | 33 ULONGLONG end_cpu = win_cpu_time(); |
| 34 return static_cast<double>(end_cpu - fStartCpu) / 10000.0L; | 34 return static_cast<double>(end_cpu - fStartCpu) / 10000.0L; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // On recent Intel chips (roughly, "has Core or Atom in its name") __rdtsc will
always tick | 37 // On recent Intel chips (roughly, "has Core or Atom in its name") __rdtsc will
always tick |
| 38 // at the CPU's maximum rate, even while power management clocks the CPU up and
down. | 38 // at the CPU's maximum rate, even while power management clocks the CPU up and
down. |
| 39 // That's great, because it makes measuring wall time super simple. | 39 // That's great, because it makes measuring wall time super simple. |
| 40 | 40 |
| 41 static double ticks_to_ms(unsigned _int64 ticks) { |
| 42 // This seems to, weirdly, give the CPU frequency in kHz. That's exactly wh
at we want! |
| 43 LARGE_INTEGER freq_khz; |
| 44 QueryPerformanceFrequency(&freq_khz); |
| 45 |
| 46 return static_cast<double>(ticks) / static_cast<double>(freq_khz.QuadPart); |
| 47 } |
| 48 |
| 41 void SysTimer::startWall() { | 49 void SysTimer::startWall() { |
| 42 fStartWall = __rdtsc(); | 50 fStartWall = __rdtsc(); |
| 43 } | 51 } |
| 44 | 52 |
| 45 double SysTimer::endWall() { | 53 double SysTimer::endWall() { |
| 46 unsigned __int64 end = __rdtsc(); | 54 unsigned __int64 end = __rdtsc(); |
| 55 return ticks_to_ms(end - fStartWall); |
| 56 } |
| 47 | 57 |
| 48 // This seems to, weirdly, give the CPU frequency in kHz. That's exactly wh
at we want! | 58 double GetTimeMs() { |
| 49 LARGE_INTEGER freq_khz; | 59 static const unsigned __int64 launchTime = __rdtsc(); |
| 50 QueryPerformanceFrequency(&freq_khz); | 60 return ticks_to_ms(__rdtsc() - launchTime); |
| 51 | |
| 52 return static_cast<double>(end - fStartWall) / static_cast<double>(freq_khz.
QuadPart); | |
| 53 } | 61 } |
| OLD | NEW |