-
Notifications
You must be signed in to change notification settings - Fork 149
/
real-time.h
41 lines (32 loc) · 1.05 KB
/
real-time.h
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
/* This file is a part of MIR project.
Copyright (C) 2018-2024 Vladimir Makarov <[email protected]> and logzero <[email protected]>
*/
#ifndef _WIN32
#include <sys/time.h>
static double __attribute__ ((unused)) real_sec_time (void) {
struct timeval tv;
gettimeofday (&tv, NULL);
return tv.tv_usec / 1000000.0 + tv.tv_sec;
}
static double __attribute__ ((unused)) real_usec_time (void) {
struct timeval tv;
gettimeofday (&tv, NULL);
return tv.tv_usec + tv.tv_sec * 1000000.0;
}
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// does not return actual time, use as a stopwatch only
static double real_sec_time (void) {
LARGE_INTEGER freq, count;
if (QueryPerformanceFrequency (&freq) && QueryPerformanceCounter (&count))
return (double) count.QuadPart / (double) freq.QuadPart;
return 0.0;
}
static double real_usec_time (void) {
LARGE_INTEGER freq, count;
if (QueryPerformanceFrequency (&freq) && QueryPerformanceCounter (&count))
return (double) count.QuadPart / ((double) freq.QuadPart * 1.0E-6);
return 0.0;
}
#endif