Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Timer.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "Timer.h"
14 
15 #include <ctime>
16 
17 
18 using namespace kome::core;
19 
20 
21 #include <crtdbg.h>
22 #ifdef _DEBUG
23  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
24  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
25 #endif // _DEBUG
26 
27 
28 
29 // constructor
31  reset();
32 }
33 
34 // destrctor
36 }
37 
38 // reset timer
39 void Timer::reset() {
40  m_total = 0.0;
41  m_start = 0;
42  m_stopped = true;
43 }
44 
45 // start timer
46 void Timer::start() {
47  m_start = std::clock();
48  m_stopped = false;
49 }
50 
51 // stop timer
52 double Timer::stop() {
53  // total time
54  const double t = getTime();
55  m_total += getTime();
56 
57  // set start time
58  m_start = std::clock();
59 
60  // stopped
61  m_stopped = true;
62 
63  return t;
64 }
65 
66 // get time
67 double Timer::getTime() {
68  // get time
69  double t = 0.0;
70 
71  if( !m_stopped ) {
72  // current
73  clock_t current = std::clock();
74 
75  // time
76  t = (double)( current - m_start ) / (double)( CLOCKS_PER_SEC );
77  }
78 
79  return t;
80 }
81 
82 // get total time
84  double t = m_total;
85  t += getTime();
86  return t;
87 }
double getTime()
gets time
Definition: Timer.cpp:67
double m_total
Definition: Timer.h:45
void start()
starts timer
Definition: Timer.cpp:46
interfaces of Timer class
virtual ~Timer()
destructor
Definition: Timer.cpp:35
void reset()
resets timer
Definition: Timer.cpp:39
Timer()
constructor
Definition: Timer.cpp:30
double getTotalTime()
gets total time
Definition: Timer.cpp:83
double stop()
stops timer
Definition: Timer.cpp:52
clock_t m_start
Definition: Timer.h:42
bool m_stopped
Definition: Timer.h:48