Fabcoin Core  0.16.2
P2P Digital Currency
hrtimer.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_HRTIMER_H
2 #define CRYPTOPP_HRTIMER_H
3 
4 #include "config.h"
5 
6 #if !defined(HIGHRES_TIMER_AVAILABLE) || (defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(THREAD_TIMER_AVAILABLE))
7 #include <time.h>
8 #endif
9 
11 
12 #ifdef HIGHRES_TIMER_AVAILABLE
13  typedef word64 TimerWord;
14 #else
15  typedef clock_t TimerWord;
16 #endif
17 
21 {
22 public:
23  enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
24  TimerBase(Unit unit, bool stuckAtZero)
25  : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false)
26  , m_start(0), m_last(0) {}
27 
28  virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0
29  virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds
30 
31  void StartTimer();
32  double ElapsedTimeAsDouble();
33  unsigned long ElapsedTime();
34 
35 private:
36  double ConvertTo(TimerWord t, Unit unit);
37 
38  Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
39  bool m_stuckAtZero, m_started;
40  TimerWord m_start, m_last;
41 };
42 
48 class ThreadUserTimer : public TimerBase
49 {
50 public:
51  ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
52  TimerWord GetCurrentTimerValue();
53  TimerWord TicksPerSecond();
54 };
55 
58 {
59 public:
60  Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
61  TimerWord GetCurrentTimerValue();
62  TimerWord TicksPerSecond();
63 };
64 
66 
67 #endif
clock_t TimerWord
Definition: hrtimer.h:15
high resolution timer
Definition: hrtimer.h:57
Timer(Unit unit=TimerBase::SECONDS, bool stuckAtZero=false)
Definition: hrtimer.h:60
Unit m_timerUnit
Definition: hrtimer.h:38
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Library configuration file.
TimerBase(Unit unit, bool stuckAtZero)
Definition: hrtimer.h:24
bool m_stuckAtZero
Definition: hrtimer.h:39
unsigned long long word64
Definition: config.h:240
ThreadUserTimer(Unit unit=TimerBase::SECONDS, bool stuckAtZero=false)
Definition: hrtimer.h:51
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
TimerWord m_start
Definition: hrtimer.h:40
#define NAMESPACE_END
Definition: config.h:201
Measure CPU time spent executing instructions of this thread (if supported by OS) ...
Definition: hrtimer.h:48
#define CRYPTOPP_DLL
Definition: config.h:704
Base class for timers.
Definition: hrtimer.h:20