-
Notifications
You must be signed in to change notification settings - Fork 22
/
timer.h
65 lines (46 loc) · 1.09 KB
/
timer.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
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef VECCORE_TIMER_H
#define VECCORE_TIMER_H
#include <chrono>
using namespace std::chrono;
template <class unit = nanoseconds>
class Timer {
using clock = high_resolution_clock;
public:
Timer() : fStart(), fStop() { Start(); }
void Reset() { Start(); }
void Start() { fStart = clock::now(); }
double Elapsed()
{
fStop = clock::now();
return duration_cast<unit>(fStop - fStart).count();
}
private:
high_resolution_clock::time_point fStart, fStop;
};
#if !defined(__CUDA_ARCH__) && !defined(__NVCOMPILER) \
&& (defined(__x86_64__) || defined(_M_X64) \
|| defined(__i386__) || defined(_M_IX86))
#define VECCORE_TIMER_CYCLES
#ifdef _MSC_VER
# include <intrin.h>
#else
# include <x86intrin.h>
#endif
class cycles {
};
template <>
class Timer<cycles> {
public:
Timer() { Start(); }
void Reset() { Start(); }
void Start() { fStart = GetCycleCount(); }
double Elapsed() { return static_cast<double>(GetCycleCount() - fStart); }
private:
unsigned long long int fStart;
inline unsigned long long int GetCycleCount()
{
return __rdtsc();
}
};
#endif
#endif