-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.cpp
85 lines (57 loc) · 1.45 KB
/
benchmark.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <chrono>
#include <map>
#include "benchmark.h"
#undef DEFAULT_ARG
#define DEFAULT_ARG
using namespace std;
typedef chrono::high_resolution_clock hrClock;
typedef chrono::steady_clock::time_point tPoint;
typedef chrono::seconds seconds;
typedef chrono::milliseconds milliseconds;
typedef chrono::microseconds microseconds;
typedef chrono::nanoseconds nanoseconds;
using chrono::duration_cast;
static auto timers = map<MAP_KEY, pair<tPoint, tPoint>>();
START_TIMER {
ARG_REPLACE
if (!timers.contains(n))
timers[n].first = hrClock::now();
RETURN_VOID;
}
STOP_TIMER {
tPoint now = hrClock::now();
ARG_REPLACE
if (timers.contains(n))
timers[n].second = now;
RETURN_VOID;
}
GET_TIMER_SECONDS {
ARG_REPLACE
if (timers.contains(n))
RETURN_TIME(duration_cast<seconds>(timers[n].second - timers[n].first).count());
RETURN_ZERO;
}
GET_TIMER_MILLI_SECONDS {
ARG_REPLACE
if (timers.contains(n))
RETURN_TIME(duration_cast<milliseconds>(timers[n].second - timers[n].first).count());
RETURN_ZERO;
}
GET_TIMER_MICRO_SECONDS {
ARG_REPLACE
if (timers.contains(n))
RETURN_TIME(duration_cast<microseconds>(timers[n].second - timers[n].first).count());
RETURN_ZERO;
}
GET_TIMER_NANO_SECONDS {
ARG_REPLACE
if (timers.contains(n))
RETURN_TIME(duration_cast<nanoseconds>(timers[n].second - timers[n].first).count());
RETURN_ZERO;
}
DESTROY_TIMER {
ARG_REPLACE
if (timers.contains(n))
timers.erase(n);
RETURN_VOID;
}