MyraMath
Stopwatch.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_UTILITY_STOPWATCH_H
7 #define MYRAMATH_UTILITY_STOPWATCH_H
8 
29 #include <myramath/MYRAMATH_EXPORT.h>
30 #include <myramath/utility/Timer.h>
31 
32 namespace myra {
33 
35 class MYRAMATH_EXPORT Stopwatch
36  {
37  public:
38 
40  Stopwatch() { total = 0.0; }
41 
43  void start() { timer.reset(); }
44  void stop() { total += timer.elapsed_time(); }
45 
47  double read() const { return total; }
48 
49  private:
50 
51  // Used to measure the time of each start()/stop() pair.
52  Timer timer;
53 
54  // Accumulates total time.
55  double total;
56  };
57 
58 } // namespace myra
59 
60 #endif
double read() const
Returns the total time accumulated over all start/stop pairs.
Definition: Stopwatch.h:47
void start()
Bookend around a function to be timed.
Definition: Stopwatch.h:43
Stopwatch()
Constructor, initializes total time to zero.
Definition: Stopwatch.h:40
A multishot timing class, delegates to Timer.
Definition: Stopwatch.h:35
Simplistic timing class, might dispatch to platform specific timers depending upon environment...
Definition: syntax.dox:1
Measures elapsed time.
Definition: Timer.h:19