ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timings.h
Go to the documentation of this file.
1 #ifndef MAQUIS_TIMINGS_H
2 #define MAQUIS_TIMINGS_H
3 
4 #include <string>
5 #include <fstream>
6 #include <iostream>
7 #include <boost/chrono.hpp>
8 #include "utils/io.hpp"
9 
10 #ifdef MAQUIS_OPENMP
11 #include "omp.h"
12 #endif
13 
14 class Timer
15 {
16 public:
17  Timer(std::string name_)
18  : val(0.0), name(name_), nCounter(0) { }
19 
20  ~Timer() { maquis::cout << name << " " << val << ", nCounter : " << nCounter << std::endl; }
21 
22  Timer & operator+=(double t) {
23  val += t;
24  return *this;
25  }
26 
27  void begin() {
28  t0 = boost::chrono::system_clock::now();
29  }
30 
31  void end() {
32  nCounter += 1;
33  boost::chrono::duration<double> sec = boost::chrono::system_clock::now() - t0;
34  val += sec.count();
35  }
36 
37  double get_time() const {
38  return val;
39  }
40 
41  friend std::ostream& operator<< (std::ostream& os, Timer const& timer) {
42  os << timer.name << " " << timer.val << ", nCounter : " << timer.nCounter;
43  return os;
44  }
45 
46 protected:
47  double val;
48  std::string name;
49  boost::chrono::system_clock::time_point t0;
50  unsigned long long nCounter;
51 };
52 
53 #ifdef MAQUIS_OPENMP
54 class TimerOMP : public Timer {
55 public:
56  TimerOMP(std::string name_) : Timer(name_), timer_start(0.0), timer_end(0.0){}
57 
58  ~TimerOMP(){}
59 
60  void begin() {
61  timer_start = omp_get_wtime();
62  }
63 
64  void end() {
65  timer_end = omp_get_wtime();
66  val += timer_end - timer_start;
67  }
68 private:
69  double timer_start, timer_end;
70 };
71 #endif
72 
73 
74 #endif
boost::chrono::system_clock::time_point t0
Definition: timings.h:49
friend std::ostream & operator<<(std::ostream &os, Timer const &timer)
Definition: timings.h:41
Definition: timings.h:14
double get_time() const
Definition: timings.h:37
std::string name
Definition: timings.h:48
void end()
Definition: timings.h:31
Timer(std::string name_)
Definition: timings.h:17
unsigned long long nCounter
Definition: timings.h:50
double val
Definition: timings.h:47
Timer & operator+=(double t)
Definition: timings.h:22
~Timer()
Definition: timings.h:20
void begin()
Definition: timings.h:27