Pol  Revision:cb584c9
timer.h
Go to the documentation of this file.
1 #ifndef CLIB_TIMER_H
2 #define CLIB_TIMER_H
3 
4 #include <chrono>
5 #include <string>
6 
7 namespace Pol
8 {
9 namespace Tools // global ns is enough polluted
10 {
11 // automatically print into the console
12 struct DebugT
13 {
14  static void print( const std::string& name, long long time );
15 };
16 // silent version
17 struct SilentT
18 {
19  static void print( const std::string& name, long long time );
20 };
21 
22 
23 // simple Timer class
24 // instantiate it by giving it a name and wait for destroy
25 // or use start/stop methods to control it
26 // uses by default Silent version for calculation and stuff
27 // or template version for Debug print
28 template <class printer = SilentT>
29 class Timer : protected printer
30 {
31  typedef std::chrono::high_resolution_clock Clock;
32  typedef std::chrono::milliseconds ms;
33 
34 public:
35  Timer( std::string name );
36  Timer();
37  ~Timer();
38  void start();
39  void stop();
40  // no one wants to know more then milliseconds..
41  long long ellapsed() const;
42  double ellapsed_s() const;
43  void print() const;
44 
45 private:
46  std::string _name;
47  Clock::time_point _start;
48  Clock::time_point _end;
49 };
50 
52 {
53 public:
54  typedef std::chrono::high_resolution_clock Clock;
55  typedef std::chrono::microseconds time_mu;
56 
57  HighPerfTimer();
58  time_mu ellapsed() const;
59 
60 private:
61  Clock::time_point _start;
62 };
63 }
64 }
65 
66 #endif // CLIB_TIMER_H
Clock::time_point _end
Definition: timer.h:48
std::chrono::high_resolution_clock Clock
Definition: timer.h:54
std::string _name
Definition: timer.h:46
Clock::time_point _start
Definition: timer.h:47
std::chrono::milliseconds ms
Definition: timer.h:32
std::chrono::high_resolution_clock Clock
Definition: timer.h:31
Clock::time_point _start
Definition: timer.h:61
std::string name
Definition: osmod.cpp:943
static void print(const std::string &name, long long time)
Definition: timer.cpp:9
std::chrono::microseconds time_mu
Definition: timer.h:55
Definition: berror.cpp:12