Security Scol plugin
hrtimer.h
Go to the documentation of this file.
1// hrtimer.h - originally written and placed in the public domain by Wei Dai
2
5
6#ifndef CRYPTOPP_HRTIMER_H
7#define CRYPTOPP_HRTIMER_H
8
9#include "config.h"
10
11#if !defined(HIGHRES_TIMER_AVAILABLE) || (defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(THREAD_TIMER_AVAILABLE))
12#include <time.h>
13#endif
14
15NAMESPACE_BEGIN(CryptoPP)
16
17#ifdef HIGHRES_TIMER_AVAILABLE
19 typedef word64 TimerWord;
20#else
22 typedef clock_t TimerWord;
23#endif
24
27class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
28{
29public:
34 enum Unit {
37 SECONDS = 0,
46 NANOSECONDS
47 };
48
52 TimerBase(Unit unit, bool stuckAtZero)
53 : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false)
54 , m_start(0), m_last(0) {}
55
59
65
67 void StartTimer();
68
78 double ElapsedTimeAsDouble();
79
89 unsigned long ElapsedTime();
90
91private:
92 double ConvertTo(TimerWord t, Unit unit);
93
94 Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
95 bool m_stuckAtZero, m_started;
96 TimerWord m_start, m_last;
97};
98
109{
110public:
114 ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
117};
118
121class CRYPTOPP_DLL Timer : public TimerBase
122{
123public:
127 Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
128 TimerWord GetCurrentTimerValue();
129 TimerWord TicksPerSecond();
130};
131
132NAMESPACE_END
133
134#endif
Measure CPU time spent executing instructions of this thread.
Definition hrtimer.h:109
TimerWord GetCurrentTimerValue()
Retrieve the current timer value.
Definition hrtimer.cpp:121
TimerWord TicksPerSecond()
Retrieve ticks per second.
Definition hrtimer.cpp:159
ThreadUserTimer(Unit unit=TimerBase::SECONDS, bool stuckAtZero=false)
Construct a ThreadUserTimer.
Definition hrtimer.h:114
Base class for timers.
Definition hrtimer.h:28
TimerBase(Unit unit, bool stuckAtZero)
Construct a TimerBase.
Definition hrtimer.h:52
virtual TimerWord TicksPerSecond()=0
Retrieve ticks per second.
virtual TimerWord GetCurrentTimerValue()=0
Retrieve the current timer value.
Unit
Unit of measure.
Definition hrtimer.h:34
@ MILLISECONDS
Timer unit is milliseconds.
Definition hrtimer.h:40
@ MICROSECONDS
Timer unit is microseconds.
Definition hrtimer.h:43
@ SECONDS
Timer unit is seconds.
Definition hrtimer.h:37
High resolution timer.
Definition hrtimer.h:122
Timer(Unit unit=TimerBase::SECONDS, bool stuckAtZero=false)
Construct a Timer.
Definition hrtimer.h:127
Library configuration file.
clock_t TimerWord
TimerWord is a clock_t.
Definition hrtimer.h:22