Crypto++
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) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {}
23 
24  virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0
25  virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds
26 
27  void StartTimer();
28  double ElapsedTimeAsDouble();
29  unsigned long ElapsedTime();
30 
31 private:
32  double ConvertTo(TimerWord t, Unit unit);
33 
34  Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
35  bool m_stuckAtZero, m_started;
36  TimerWord m_start, m_last;
37 };
38 
39 //! measure CPU time spent executing instructions of this thread (if supported by OS)
40 /*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and others wall clock time.
41 */
42 class ThreadUserTimer : public TimerBase
43 {
44 public:
45  ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
46  TimerWord GetCurrentTimerValue();
47  TimerWord TicksPerSecond();
48 };
49 
50 //! high resolution timer
51 class CRYPTOPP_DLL Timer : public TimerBase
52 {
53 public:
54  Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
55  TimerWord GetCurrentTimerValue();
56  TimerWord TicksPerSecond();
57 };
58 
59 NAMESPACE_END
60 
61 #endif
high resolution timer
Definition: hrtimer.h:51
measure CPU time spent executing instructions of this thread (if supported by OS) ...
Definition: hrtimer.h:42
_
Definition: hrtimer.h:18