-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhp_timer.cpp
71 lines (54 loc) · 1.28 KB
/
hp_timer.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// hp_timer.cpp
#include "hp_timer.h"
#include <stdio.h>
#ifdef _WIN32
int64_t __freq;
int64_t __time_at_init;
void initTimer()
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
__freq = freq.QuadPart;
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
__time_at_init = now.QuadPart;
}
void shutTimer() {}
#elif defined(__MACH__)
clock_serv_t __clock_rt;
unsigned int __tv_sec_at_init;
void initTimer()
{
host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &__clock_rt);
// natural_t attributes[4];
// mach_msg_type_number_t count;
// clock_get_attributes(__clock_rt, CLOCK_GET_TIME_RES,
// (clock_attr_t)&attributes, &count);
// printf("MacOS X: realtime clock resolution: %u ns\n", attributes[0]);
mach_timespec_t mts;
clock_get_time(__clock_rt, &mts);
__tv_sec_at_init = mts.tv_sec;
}
void shutTimer()
{
mach_port_deallocate(mach_task_self(), __clock_rt);
}
#elif defined(__linux__)
time_t __tv_sec_at_init = 0;
void initTimer()
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
__tv_sec_at_init = ts.tv_sec;
}
void shutTimer() {}
#else
time_t __tv_sec_at_init = 0;
void initTimer()
{
struct timeval tv;
gettimeofday(&tv, NULL);
__tv_sec_at_init = ts.tv_sec;
}
void shutTimer() {}
#endif