OpenMPCD
Stopwatch.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the `OpenMPCD::Profiling::Stopwatch` class.
4  */
5 
6 #ifndef OPENMPCD_PROFILING_STOPWATCH_HPP
7 #define OPENMPCD_PROFILING_STOPWATCH_HPP
8 
9 #include <boost/chrono.hpp>
10 
11 namespace OpenMPCD
12 {
13 namespace Profiling
14 {
15 
16 /**
17  * Marks a code region.
18  * The marked region starts with the construction of an instance of this class,
19  * and ends with its destruction.
20  */
21 class Stopwatch
22 {
23 public:
24  typedef boost::chrono::microseconds::rep MicrosecondDuration;
25  /**< An integral type that represents a duration of time in terms of
26  microseconds.*/
27 
28 public:
29  /**
30  * The constructor.
31  *
32  * Upon construction, the stopwatch starts measuring time.
33  */
35  : startingTime(boost::chrono::high_resolution_clock::now())
36  {
37  }
38 
39 private:
40  Stopwatch(const Stopwatch&); ///< The copy constructor.
41 
42 public:
43  /**
44  * The destructor.
45  */
47  {
48  }
49 
50 public:
51  /**
52  * Returns the number of microseconds that have elapsed since the stopwatch
53  * started measuring.
54  */
56  {
57  const boost::chrono::high_resolution_clock::time_point now =
58  boost::chrono::high_resolution_clock::now();
59  const boost::chrono::microseconds m =
60  boost::chrono::duration_cast<boost::chrono::microseconds>(
61  now - startingTime);
62 
63  return m.count();
64  }
65 
66 private:
67  const Stopwatch& operator=(const Stopwatch&); ///< The assignment operator.
68 
69 private:
70  const boost::chrono::high_resolution_clock::time_point startingTime;
71  ///< The point in time the stopwatch started measuring.
72 }; //class Stopwatch
73 } //namespace Profiling
74 } //namespace OpenMPCD
75 
76 #endif //OPENMPCD_PROFILING_STOPWATCH_HPP
OpenMPCD::Profiling::Stopwatch::MicrosecondDuration
boost::chrono::microseconds::rep MicrosecondDuration
An integral type that represents a duration of time in terms of microseconds.
Definition: Stopwatch.hpp:24
OpenMPCD::Profiling::Stopwatch
Marks a code region.
Definition: Stopwatch.hpp:21
OpenMPCD::Profiling::Stopwatch::Stopwatch
Stopwatch()
The constructor.
Definition: Stopwatch.hpp:34
OpenMPCD::Profiling::Stopwatch::~Stopwatch
~Stopwatch()
The destructor.
Definition: Stopwatch.hpp:46
OpenMPCD::Profiling::Stopwatch::getElapsedMicroseconds
const MicrosecondDuration getElapsedMicroseconds() const
Returns the number of microseconds that have elapsed since the stopwatch started measuring.
Definition: Stopwatch.hpp:55