-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtimer.h
More file actions
51 lines (43 loc) · 883 Bytes
/
Copy pathtimer.h
File metadata and controls
51 lines (43 loc) · 883 Bytes
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
#ifndef TIMER_ANALYZER_H
#define TIMER_ANALYZER_H
#include <cstdlib>
#include <sys/time.h>
namespace detect_similar
{
enum TimeAnalyzerIds {
TimeTotal,
TimeProcess,
TimeNone
};
/**
@brief
Calculate time
*/
class TimerAnalyzer {
public:
static inline void start(TimeAnalyzerIds id = TimeTotal)
{
if (id != TimeTotal && id != TimeProcess) return;
if (!enabled) return;
data[id] -= microtime();
}
static inline void stop(TimeAnalyzerIds id = TimeTotal)
{
if (!enabled) return;
data[id] += microtime();
}
static inline float secs(TimeAnalyzerIds id = TimeTotal)
{
return data[id] * 1e-6;
}
static inline long unsigned int microtime()
{
struct timeval tv;
gettimeofday(&tv,NULL);
return (long unsigned int) (1e6*tv.tv_sec + tv.tv_usec);
}
static bool enabled;
static int data[TimeNone];
};
} //namespace detect_similar
#endif //TIMER_ANALYZER_H