-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTimer.cpp
More file actions
43 lines (42 loc) · 1.14 KB
/
Timer.cpp
File metadata and controls
43 lines (42 loc) · 1.14 KB
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
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__MACH__)
#include <time.h>
#include <mach/clock.h>
#include <mach/mach.h>
#else
#include <time.h>
#endif
#include "Core/Utils.h"
double get_time_milliseconds()
{
#if defined(_WIN32)
static double freq = 0.0;
if (freq == 0.0) {
LARGE_INTEGER li;
if (!QueryPerformanceFrequency(&li))
die("clock failure");
freq = (double)li.QuadPart / 1000.0;
}
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return (double)li.QuadPart / freq;
#elif defined(__MACH__)
struct timespec t;
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
if (clock_get_time(cclock, &mts) != KERN_SUCCESS) {
die("clock failure");
}
mach_port_deallocate(mach_task_self(), cclock);
t.tv_sec = mts.tv_sec;
t.tv_nsec = mts.tv_nsec;
return (double)t.tv_sec * 1000.0 + (double)t.tv_nsec / 1000000.0;
#else
struct timespec t;
if (clock_gettime(CLOCK_MONOTONIC, &t) != 0)
die("clock failure");
return (double)t.tv_sec * 1000.0 + (double)t.tv_nsec / 1000000.0;
#endif
}