Pottu
DurationCounter.hpp
Go to the documentation of this file.
1 
6 #ifndef H_POTTU_DURATIONCOUNTER
7 #define H_POTTU_DURATIONCOUNTER
8 
9 
10 #include <chrono>
11 
12 
14  using clock_t = std::chrono::steady_clock;
15 
16  void start() noexcept {
17  if( running )
18  return;
19  currentStart = clock_t::now();
20  running = true;
21  }
22 
23  void stop() noexcept {
24  if( running ) {
25  running = false;
26  total += clock_t::now()-currentStart;
27  }
28  }
29 
30  double get() const noexcept {
31  if( running )
32  return ( std::chrono::duration<double>( (total + (clock_t::now()-currentStart)) ) ).count();
33  return ( std::chrono::duration<double>( total ) ).count();
34  }
35 
36  clock_t::duration total{0};
37  bool running{false};
38  clock_t::time_point currentStart;
39 };
40 
41 
42 #endif
Definition: DurationCounter.hpp:13