-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
52 lines (43 loc) · 1009 Bytes
/
util.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
42
43
44
45
46
47
48
49
50
51
52
//
// Created by Jovasa on 9.1.2024.
//
#ifndef VISUALIZER_UTIL_H
#define VISUALIZER_UTIL_H
#ifdef _MSC_VER
#include <windows.h>
typedef LARGE_INTEGER TimeStamp;
static LARGE_INTEGER Frequency;
//QueryPerformanceFrequency(&Frequency);
#define GET_TIME(ts, rs) \
do {static TimeStamp StartingTime; \
QueryPerformanceCounter(&StartingTime); \
rs = StartingTime.QuadPart * 1000000000 / Frequency.QuadPart; } while(0)
#else
typedef struct timespec TimeStamp;
#define GET_TIME(ts, rs) \
do {clock_gettime(CLOCK_REALTIME, &ts); \
rs = ts.tv_sec * 1000000000 + ts.tv_nsec;} while(0)
#endif
template<typename T>
T ceil_div(T a, T b) {
return (a + b - 1) / b;
}
template<typename T>
T floor_div(T a, T b) {
return a / b;
}
template<typename T>
T max(T a, T b) {
return a > b ? a : b;
}
template<typename T>
T clamp(T value, T min, T max) {
if (value < min) {
return min;
}
if (value > max) {
return max;
}
return value;
}
#endif //VISUALIZER_UTIL_H