forked from ljdongysu/rkv2_super
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
68 lines (52 loc) · 1.35 KB
/
Copy pathtimer.h
File metadata and controls
68 lines (52 loc) · 1.35 KB
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
#ifndef TIMER_H
#define TIMER_H
#include <sys/time.h> //test
#include <iostream>
class Timer
{
public:
Timer()
{
Start();
}
double Timing(const std::string message = "", bool print = false)
{
gettimeofday(&end, nullptr);
double timeuse = (1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec -
start.tv_usec) * 1.0 / 1000;
if ("" != message)
{
if (print)
{
std::cout << "use time(" << message << "): "
<< timeuse << "ms" << std::endl;
}
}
Start();
return timeuse;
}
std::string TimingStr(const std::string message = "", bool print = false)
{
gettimeofday(&end, nullptr);
double timeuse = (1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec -
start.tv_usec) * 1.0 / 1000;
std::ostringstream useTime("");
useTime << "use time(" << message << "): "
<< timeuse << "ms";
std::string useTimeStr = useTime.str();
if (print)
{
std::cout << useTimeStr << std::endl;
}
Start();
return useTimeStr;
}
private:
void Start()
{
gettimeofday(&start, nullptr);
}
private:
struct timeval start, end;
};
#endif // TIMER_H