Crypto++  5.6.3
Free C++ class library of cryptographic schemes
hrtimer.h
1 #ifndef CRYPTOPP_HRTIMER_H
2 #define CRYPTOPP_HRTIMER_H
3 
4 #include "config.h"
5 #ifndef HIGHRES_TIMER_AVAILABLE
6 #include <time.h>
7 #endif
8 
9 NAMESPACE_BEGIN(CryptoPP)
10 
11 #ifdef HIGHRES_TIMER_AVAILABLE
12  typedef word64 TimerWord;
13 #else
14  typedef clock_t TimerWord;
15 #endif
16 
17 //! _
18 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
19 {
20 public:
21  enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
22  TimerBase(Unit unit, bool stuckAtZero)
23  : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false)
24  , m_start(0), m_last(0) {}
25 
26  virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0
27  virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds
28 
29  void StartTimer();
30  double ElapsedTimeAsDouble();
31  unsigned long ElapsedTime();
32 
33 private:
34  double ConvertTo(TimerWord t, Unit unit);
35 
36  Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
37  bool m_stuckAtZero, m_started;
38  TimerWord m_start, m_last;
39 };
40 
41 //! measure CPU time spent executing instructions of this thread (if supported by OS)
42 /*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and others wall clock time.
43 */
44 class ThreadUserTimer : public TimerBase
45 {
46 public:
47  ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
48  TimerWord GetCurrentTimerValue();
49  TimerWord TicksPerSecond();
50 };
51 
52 //! high resolution timer
53 class CRYPTOPP_DLL Timer : public TimerBase
54 {
55 public:
56  Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
57  TimerWord GetCurrentTimerValue();
58  TimerWord TicksPerSecond();
59 };
60 
61 NAMESPACE_END
62 
63 #endif
high resolution timer
Definition: hrtimer.h:53
Library configuration file.
Crypto++ library namespace.
measure CPU time spent executing instructions of this thread (if supported by OS) ...
Definition: hrtimer.h:44
_
Definition: hrtimer.h:18