RealTimeStopwatch.cc
Go to the documentation of this file.
1 #include <sys/time.h>
2 #include "RealTimeStopwatch.h"
3 
4 using namespace utl;
5 
6 
8  fIsStopped(!start),
9  fTimeSum(0)
10 {
11  if (start)
12  gettimeofday(&fStart, 0);
13 }
14 
15 
16 void
18 {
19  fIsStopped = true;
20  fTimeSum = 0;
21 }
22 
23 
24 void
26 {
27  if (fIsStopped) {
28  gettimeofday(&fStart, 0);
29  fIsStopped = false;
30  }
31 }
32 
33 
34 double
36 {
37  if (fIsStopped)
38  return fTimeSum;
39  else {
40  struct timeval stop;
41  gettimeofday(&stop, 0);
42  fIsStopped = true;
43  return fTimeSum +=
44  (stop.tv_sec - fStart.tv_sec)*second +
45  (stop.tv_usec - fStart.tv_usec)*microsecond;
46  }
47 }
48 
49 
50 double
52 {
53  if (fIsStopped)
54  return fTimeSum;
55  else {
56  struct timeval stop;
57  gettimeofday(&stop, 0);
58  return fTimeSum + (stop.tv_sec - fStart.tv_sec)*second +
59  (stop.tv_usec - fStart.tv_usec)*microsecond;
60  }
61 }
62 
63 
64 // Configure (x)emacs for this file ...
65 // Local Variables:
66 // mode: c++
67 // End:
constexpr double second
Definition: AugerUnits.h:145
RealTimeStopwatch(const bool start=true)
double Stop()
returns time since last call to Start()
constexpr double microsecond
Definition: AugerUnits.h:147

, generated on Tue Sep 26 2023.