OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
BasChronometer.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6// OpenTrep
9
10namespace OPENTREP {
11
12 // //////////////////////////////////////////////////////////////////////
13 BasChronometer::BasChronometer () : _startTimeLaunched (false) {
14 }
15
16 // //////////////////////////////////////////////////////////////////////
18 // Get the time-stamp of now, and store it for later use
19 _startTime = boost::posix_time::microsec_clock::local_time();
20
21 // Update the boolean which states whether the chronometer
22 // is launched
23 _startTimeLaunched = true;
24 }
25
26 // //////////////////////////////////////////////////////////////////////
27 double BasChronometer::elapsed () const {
28 assert (_startTimeLaunched == true);
29
30 // Get the time-stamp of now
31 const boost::posix_time::ptime lStopTime =
32 boost::posix_time::microsec_clock::local_time();
33
34 // Calculate the time elapsed since the last time-stamp
35 const boost::posix_time::time_duration lElapsedTime =
36 lStopTime - _startTime;
37
38 // Derived the corresponding number of milliseconds
39 const double lElapsedTimeInMicroSeconds =
40 static_cast<const double> (lElapsedTime.total_microseconds());
41
42 /*OPENTREP_LOG_DEBUG ("Elapsed: " << lElapsedTime
43 << "; (micros): "
44 << lElapsedTimeInMicroSeconds / 1e6);*/
45
46 // The elapsed time given in return is expressed in seconds
47 return (lElapsedTimeInMicroSeconds / 1e6);
48 }
49
50}