Medusa  1.1
Coordinate Free Mehless Method implementation
Timer.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_UTILS_TIMER_HPP_
2 #define MEDUSA_BITS_UTILS_TIMER_HPP_
3 
11 #include <medusa/Config.hpp>
12 #include <iostream>
13 #include <chrono>
14 #include <string>
15 #include <vector>
16 
17 namespace mm {
18 
29 class Timer {
30  protected:
31  typedef std::chrono::steady_clock::time_point time_type;
32  std::vector<std::string> labels_;
33  std::vector<time_type> times_;
34 
36  void showTimings(int from, int to, std::ostream& os = std::cout) const;
38  int getID(const std::string& label) const;
40  time_type timeAt(int id) const;
41  public:
43  void addCheckPoint(const std::string& label);
44 
49  void showTimings(std::ostream& os = std::cout) const;
54  void showTimings(const std::string& from, const std::string& to,
55  std::ostream& os = std::cout) const;
57  time_type timeAt(const std::string& label) const;
59  double duration(const std::string& from, const std::string& to) const;
61  double durationToNow(const std::string& from) const;
63  int size() const { return labels_.size(); }
65  const std::vector<std::string>& labels() const { return labels_; }
67  const std::vector<time_type>& times() const { return times_; }
69  void clear();
70 
72  friend std::ostream& operator<<(std::ostream& os, const Timer& timer) {
73  timer.showTimings(os);
74  return os;
75  }
76 };
77 
78 } // namespace mm
79 
80 #endif // MEDUSA_BITS_UTILS_TIMER_HPP_
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::Timer::durationToNow
double durationToNow(const std::string &from) const
Return time difference in seconds between from and now.
Definition: Timer.cpp:63
mm::Timer::operator<<
friend std::ostream & operator<<(std::ostream &os, const Timer &timer)
Output all times between all checkpoints.
Definition: Timer.hpp:72
mm::Timer::getID
int getID(const std::string &label) const
Returns the ID of checkpoints with a given label.
Definition: Timer.cpp:67
mm::Timer::addCheckPoint
void addCheckPoint(const std::string &label)
Adds a checkpoint with given label and remembers the time at which it was added.
Definition: Timer.cpp:12
mm::Timer::time_type
std::chrono::steady_clock::time_point time_type
Time type.
Definition: Timer.hpp:31
mm::Timer
Simple timer class: add checkpoints throughout the code and measure execution time between them.
Definition: Timer.hpp:29
Config.hpp
mm::Timer::timeAt
time_type timeAt(int id) const
Return absolute time for a given id.
Definition: Timer.cpp:52
mm::Timer::labels
const std::vector< std::string > & labels() const
Return all labels.
Definition: Timer.hpp:65
mm::Timer::times_
std::vector< time_type > times_
List of checkpoint times.
Definition: Timer.hpp:33
mm::Timer::times
const std::vector< time_type > & times() const
Return all times.
Definition: Timer.hpp:67
mm::Timer::labels_
std::vector< std::string > labels_
List of checkpoint labels.
Definition: Timer.hpp:32
mm::Timer::size
int size() const
Return the number of measurements taken.
Definition: Timer.hpp:63
mm::Timer::showTimings
void showTimings(int from, int to, std::ostream &os=std::cout) const
Output timings between the checkpoints with given ids to os.
Definition: Timer.cpp:43
mm::Timer::clear
void clear()
Clear all of time points.
Definition: Timer.cpp:73
mm::Timer::duration
double duration(const std::string &from, const std::string &to) const
Return time difference in seconds between two checkpoints.
Definition: Timer.cpp:60