1 | // |
---|---|
2 | // Copyright (c) Microsoft. All rights reserved. |
3 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
4 | // |
5 | |
6 | #include "standardpch.h" |
7 | #include "logging.h" |
8 | #include "simpletimer.h" |
9 | |
10 | SimpleTimer::SimpleTimer() |
11 | { |
12 | start.QuadPart = 0; |
13 | stop.QuadPart = 0; |
14 | |
15 | BOOL retVal = ::QueryPerformanceFrequency(&proc_freq); |
16 | if (retVal == FALSE) |
17 | { |
18 | LogDebug("SimpleTimer::SimpleTimer unable to QPF. error was 0x%08x", ::GetLastError()); |
19 | ::__debugbreak(); |
20 | } |
21 | } |
22 | |
23 | SimpleTimer::~SimpleTimer() |
24 | { |
25 | } |
26 | |
27 | void SimpleTimer::Start() |
28 | { |
29 | BOOL retVal = ::QueryPerformanceCounter(&start); |
30 | if (retVal == FALSE) |
31 | { |
32 | LogDebug("SimpleTimer::Start unable to QPC. error was 0x%08x", ::GetLastError()); |
33 | ::__debugbreak(); |
34 | } |
35 | } |
36 | |
37 | void SimpleTimer::Stop() |
38 | { |
39 | BOOL retVal = ::QueryPerformanceCounter(&stop); |
40 | if (retVal == FALSE) |
41 | { |
42 | LogDebug("SimpleTimer::Stop unable to QPC. error was 0x%08x", ::GetLastError()); |
43 | ::__debugbreak(); |
44 | } |
45 | } |
46 | |
47 | double SimpleTimer::GetMilliseconds() |
48 | { |
49 | return GetSeconds() * 1000.0; |
50 | } |
51 | |
52 | double SimpleTimer::GetSeconds() |
53 | { |
54 | return ((stop.QuadPart - start.QuadPart) / (double)proc_freq.QuadPart); |
55 | } |
56 |