Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
scoped_timer.h
Go to the documentation of this file.
1 #pragma once
2 #include <chrono>
3 #include <iostream>
4 
5 namespace hgps::core {
6 
8 class ScopedTimer {
9  public:
11  using ClockType = std::chrono::steady_clock;
12 
15  ScopedTimer(const char *func) : function_{func}, start_{ClockType::now()} {}
16 
17  ScopedTimer(const ScopedTimer &) = delete;
18  ScopedTimer(ScopedTimer &&) = delete;
19  auto operator=(const ScopedTimer &) -> ScopedTimer & = delete;
20  auto operator=(ScopedTimer &&) -> ScopedTimer & = delete;
21 
24  using namespace std::chrono;
25  auto stop = ClockType::now();
26  auto duration = (stop - start_);
27  auto ms = duration_cast<milliseconds>(duration).count();
28  std::cout << ms << " ms " << function_ << '\n';
29  }
30 
31  private:
32  const char *function_ = {};
33  const ClockType::time_point start_ = {};
34 };
35 } // namespace hgps::core
Timer to printout scope execution time in milliseconds.
Definition: scoped_timer.h:8
ScopedTimer(const char *func)
Initialise a new instance of the ScopedTimer class.
Definition: scoped_timer.h:15
auto operator=(const ScopedTimer &) -> ScopedTimer &=delete
ScopedTimer(ScopedTimer &&)=delete
~ScopedTimer()
Destroys the ScopedTimer instance, printout lifetime duration.
Definition: scoped_timer.h:23
std::chrono::steady_clock ClockType
The time measuring clock.
Definition: scoped_timer.h:11
auto operator=(ScopedTimer &&) -> ScopedTimer &=delete
ScopedTimer(const ScopedTimer &)=delete
Top-level namespace for Health-GPS Core C++ API.
Definition: analysis.h:7
@ stop
Simulation has stopped, time = end.