2
2
#define CRYPTOPP_HRTIMER_H
5
#ifndef HIGHRES_TIMER_AVAILABLE
6
9
NAMESPACE_BEGIN(CryptoPP)
11
#ifdef HIGHRES_TIMER_AVAILABLE
12
typedef word64 TimerWord;
14
typedef clock_t TimerWord;
18
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
12
21
enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
13
22
TimerBase(Unit unit, bool stuckAtZero) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {}
15
virtual word64 GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0
16
virtual word64 TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds
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
19
28
double ElapsedTimeAsDouble();
20
29
unsigned long ElapsedTime();
23
double ConvertTo(word64 t, Unit unit);
32
double ConvertTo(TimerWord t, Unit unit);
25
34
Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
26
35
bool m_stuckAtZero, m_started;
27
word64 m_start, m_last;
36
TimerWord m_start, m_last;
30
39
//! measure CPU time spent executing instructions of this thread (if supported by OS)
36
45
ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
37
word64 GetCurrentTimerValue();
38
word64 TicksPerSecond();
46
TimerWord GetCurrentTimerValue();
47
TimerWord TicksPerSecond();
41
#ifdef HIGHRES_TIMER_AVAILABLE
43
50
//! high resolution timer
44
class Timer : public TimerBase
51
class CRYPTOPP_DLL Timer : public TimerBase
47
54
Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
48
word64 GetCurrentTimerValue();
49
word64 TicksPerSecond();
55
TimerWord GetCurrentTimerValue();
56
TimerWord TicksPerSecond();