fw4spl
HiResTimer.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <stdlib.h>
8 
9 #include "fwCore/HiResTimer.hpp"
10 
11 namespace fwCore
12 {
13 
14 HiResTimer::HiResTimer()
15 {
16  m_stopped = true;
17  this->reset();
18 }
19 
20 HiResTimer::~HiResTimer()
21 {
22 }
23 
25 {
26  m_stopped = false;
27 
28  m_cumulTimeInMicroSec = m_endTimeInMicroSec - m_startTimeInMicroSec;
29  m_startTimeInMicroSec = ::fwCore::HiResClock::getTimeInMicroSec();
30 }
31 
33 {
34  m_stopped = true;
35 
36  m_endTimeInMicroSec = ::fwCore::HiResClock::getTimeInMicroSec();
37 }
38 
40 {
41  bool wasStopped = m_stopped;
42  if (!wasStopped)
43  {
44  this->stop();
45  }
46  m_startTimeInMicroSec = 0.;
47  m_endTimeInMicroSec = 0.;
48  m_cumulTimeInMicroSec = initial_value;
49  if (!wasStopped)
50  {
51  this->start();
52  }
53 }
54 
56 {
57  if(!m_stopped)
58  {
59  m_endTimeInMicroSec = ::fwCore::HiResClock::getTimeInMicroSec();
60  }
61 
62  return m_cumulTimeInMicroSec + (m_endTimeInMicroSec - m_startTimeInMicroSec);
63 }
64 
65 
67 {
68  return this->getElapsedTimeInMicroSec() * 0.001;
69 }
70 
71 
73 {
74  return this->getElapsedTimeInMicroSec() * 0.000001;
75 }
76 
77 
78 } //namespace fwCore
79 
FWCORE_API void stop()
Stop the timer. stop() will not reset the timer.
Definition: HiResTimer.cpp:32
This namespace fwCore provides common foundations for FW4SPL.
Definition: BaseObject.hpp:16
double HiResClockType
Type returned by HiResClock Functions.
Definition: HiResClock.hpp:29
FWCORE_API::fwCore::HiResClock::HiResClockType getElapsedTimeInMilliSec()
Definition: HiResTimer.cpp:66
FWCORE_API void reset(::fwCore::HiResClock::HiResClockType initial_value=0.)
Reset the timer and leave it in the same state it was (started or stopped).
Definition: HiResTimer.cpp:39
FWCORE_API void start()
Start the timer.
Definition: HiResTimer.cpp:24
FWCORE_API::fwCore::HiResClock::HiResClockType getElapsedTimeInMicroSec()
Definition: HiResTimer.cpp:55
FWCORE_API::fwCore::HiResClock::HiResClockType getElapsedTimeInSec()
Definition: HiResTimer.cpp:72