forked from ruven/iipsrv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimer.h
87 lines (54 loc) · 1.72 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Timer class
/* IIP fcgi server module
Copyright (C) 2005-2013 Ruven Pillay.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _TIMER_H
#define _TIMER_H
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef WIN32
#include "../windows/Time.h"
#endif
/// Simple Timer class to allow us to time our responses
class Timer {
private:
/// Time structure
struct timeval tv;
/// Timezone structure
struct timezone tz;
/// Our start time in seconds
long start_t;
/// The microsecond component of our start time
long start_u;
public:
/// Constructor
Timer() {;};
/// Set our time
/** Initialise with our start time */
void start() {
tz.tz_minuteswest = 0;
if( gettimeofday( &tv, NULL ) == 0 ){
start_t = tv.tv_sec;
start_u = tv.tv_usec;
}
else start_t = start_u = 0;
}
/// Return time since we were initialised in microseconds
long getTime() {
if( gettimeofday( &tv, NULL ) == 0 ) return (tv.tv_sec - start_t) * 1000000 + (tv.tv_usec - start_u);
else return 0;
}
};
#endif