autoppl  v0.8
A C++ template library for probabilistic programming
stopwatch.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <chrono>
3 
4 namespace ppl {
5 namespace util {
6 
7 template <class ClockType=std::chrono::steady_clock>
8 struct StopWatch
9 {
10  void start() { start_ = ClockType::now(); }
11  void stop() { end_ = ClockType::now(); }
12 
13  double elapsed() const
14  {
15  static constexpr double nano = 1e-9;
16  return std::chrono::duration_cast<
17  std::chrono::nanoseconds>(end_-start_).count() * nano;
18  }
19 
20 private:
21  std::chrono::time_point<ClockType> start_;
22  std::chrono::time_point<ClockType> end_;
23 };
24 
25 } // namespace util
26 } // namespace ppl
ppl::util::StopWatch::stop
void stop()
Definition: stopwatch.hpp:11
ppl::util::StopWatch::elapsed
double elapsed() const
Definition: stopwatch.hpp:13
ppl::util::StopWatch::start
void start()
Definition: stopwatch.hpp:10
ppl::util::StopWatch
Definition: stopwatch.hpp:9
ppl
Definition: bounded.hpp:11