-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_util.h
More file actions
50 lines (38 loc) · 948 Bytes
/
time_util.h
File metadata and controls
50 lines (38 loc) · 948 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
#ifndef _TIME_UTIL_H_
#define _TIME_UTIL_H_
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <string.h>
#include <string>
#include <iostream>
#define TIME_MAXSIZE 100
class TIME {
public:
TIME() {
GetCurrTime();
}
~TIME() {}
TIME(int sec, int usec) {
d_time.tv_sec = sec;
d_time.tv_usec = usec;
}
TIME(const TIME &other) {
d_time = other.d_time;
strncpy(d_timestamp, other.d_timestamp, TIME_MAXSIZE);
}
void GetCurrTime() {
gettimeofday(&d_time, NULL);
}
char* CvtCurrTime(); //Return the readable time format in string
/*Calculate time duration in us*/
friend double operator-(TIME end, TIME start) {
double interval = ((end.d_time.tv_sec - start.d_time.tv_sec)*1000000.0 + (end.d_time.tv_usec - start.d_time.tv_usec));
return interval;
}
private:
struct timeval d_time; /*Current time*/
char d_timestamp[TIME_MAXSIZE];
};
#endif