-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTimer.cpp
More file actions
42 lines (32 loc) · 735 Bytes
/
Timer.cpp
File metadata and controls
42 lines (32 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "Timer.h"
Timer::Timer() {
LARGE_INTEGER freq;
if (QueryPerformanceFrequency(&freq)) {
performance_counter_present = true;
scalar = 1.0 / freq.QuadPart;
} else {
performance_counter_present = false;
scalar = 1.0 / 1000;
}
start_time = get_time_internal();
}
Timer::~Timer(){}
void Timer::reset() {
start_time = get_time_internal();
}
double Timer::get_time() {
return (double)(get_time_internal() - start_time ) * scalar;
}
long long Timer::get_time_internal() {
long long time;
if (performance_counter_present ) {
LARGE_INTEGER temp;
QueryPerformanceCounter(&temp);
time = temp.QuadPart;
} else {
time = GetTickCount();
}
return time;
}