-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.h
More file actions
executable file
·138 lines (117 loc) · 2.37 KB
/
utils.h
File metadata and controls
executable file
·138 lines (117 loc) · 2.37 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef UTILS_HEADER
#define UTILS_HEADER
#include <sys/time.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <vector>
using std::vector;
using std::pair;
typedef pair<int, int> PII;
typedef pair<int, double> PID;
typedef pair<double, double> PDD;
#define mp std::make_pair
#define ft first
#define sc second
#define EPS 1e-6
#define ASSERT(condition) \
if (!(condition)) { \
fprintf(stderr, "Assertion failed: line %d, file \"%s\"\n", \
__LINE__, __FILE__); \
fflush(stderr); \
exit(-1); \
}
void dprintf(char *format, ...);
void vprintf(char *format, ...);
void panic(char *format, ...);
class Timer
{
public:
Timer();
~Timer();
void Start();
double StepTime(); // return step process time (sec)
double Finish(bool force_update=false);
double WholeTime();
private:
struct timeval st_time, ed_time, ls_time;
bool stopped;
};
bool verbose = false;
bool debug = false;
void
dprintf(char *format, ...)
{
if (debug)
{
va_list ap;
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
fflush(stdout);
}
}
void
vprintf(char *format, ...)
{
if (verbose)
{
va_list ap;
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
fflush(stdout);
}
}
void
panic(char *format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
fflush(stdout);
exit(-1);
}
Timer::Timer()
{
Start();
}
Timer::~Timer()
{
}
void
Timer::Start()
{
gettimeofday(&st_time, NULL);
ls_time.tv_sec = st_time.tv_sec;
ls_time.tv_usec = st_time.tv_usec;
stopped = false;
}
double
Timer::StepTime()
{
struct timeval tmp;
gettimeofday(&tmp, NULL);
double res = (tmp.tv_sec - ls_time.tv_sec) + (double)(tmp.tv_usec - ls_time.tv_usec) / 1000000;
ls_time.tv_sec = tmp.tv_sec;
ls_time.tv_usec = tmp.tv_usec;
return res;
}
double
Timer::Finish(bool force_update)
{
if (!stopped || force_update)
{
stopped = true;
gettimeofday(&ed_time, NULL);
}
return this -> WholeTime();
}
double
Timer::WholeTime()
{
double res = (ed_time.tv_sec - st_time.tv_sec) + (double)(ed_time.tv_usec - st_time.tv_usec) / 1000000;
return res;
}
#endif