tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
timehelper.h
Go to the documentation of this file.
1 #ifndef _TIMEHELPER_INCLUDED_
2 #define _TIMEHELPER_INCLUDED_
3 
4 #include <string>
5 
6 ////////////////////////////////////////////////////////////////////////////////
7 // Time
8 class Time
9 {
10 public:
11  static double GetWallTime();
12  static double GetCpuTime();
13 
14  static std::string ToString(double time);
15  static std::string ToSecond(double time);
16 };
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 // Timer
20 class Timer
21 {
22 public:
23  Timer();
24  virtual ~Timer();
25 
26  void Start();
27  void Stop();
28  void Resume();
29 
30  double ElapsedCpu() const;
31  double ElapsedWall() const;
32 
33  std::string ToString() const;
34  std::string ToSecond() const;
35 
36 private:
37  double m_cpuStart;
38  double m_wallStart;
39  double m_cpuElapse;
40  double m_wallElapse;
41  bool m_stopped;
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 // ScopedTimer
46 class ScopedTimer : public Timer
47 {
48 public:
49  ScopedTimer(bool showSec = false);
50  ScopedTimer(const std::string& tag, bool showSec = false);
51  virtual ~ScopedTimer();
52 
53 private:
54  bool m_showSec;
55  std::string m_tag;
56 };
57 
58 #endif //_TIMEHELPER_INCLUDED_
59 
Definition: timehelper.h:46
double m_wallElapse
Definition: timehelper.h:40
virtual ~Timer()
Definition: timehelper.cc:94
Definition: timehelper.h:8
virtual ~ScopedTimer()
Definition: timehelper.cc:163
static std::string ToString(double time)
Definition: timehelper.cc:49
std::string ToSecond() const
Definition: timehelper.cc:140
void Stop()
Definition: timehelper.cc:106
static double GetCpuTime()
Definition: timehelper.cc:31
double ElapsedCpu() const
Definition: timehelper.cc:122
double m_cpuStart
Definition: timehelper.h:37
ScopedTimer(bool showSec=false)
Definition: timehelper.cc:150
Timer()
Definition: timehelper.cc:86
std::string m_tag
Definition: timehelper.h:55
bool m_stopped
Definition: timehelper.h:41
double m_cpuElapse
Definition: timehelper.h:39
static std::string ToSecond(double time)
Definition: timehelper.cc:74
double m_wallStart
Definition: timehelper.h:38
void Start()
Definition: timehelper.cc:97
static double GetWallTime()
Definition: timehelper.cc:12
bool m_showSec
Definition: timehelper.h:54
Definition: timehelper.h:20
double ElapsedWall() const
Definition: timehelper.cc:127
std::string ToString() const
Definition: timehelper.cc:132
void Resume()
Definition: timehelper.cc:115