Crypto++ 8.2
Free C&
hrtimer.h
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
10NAMESPACE_BEGIN(CryptoPP)
11
12#ifdef HIGHRES_TIMER_AVAILABLE
13 typedef word64 TimerWord;
14#else
15 typedef clock_t TimerWord;
16#endif
17
18/// \brief Base class for timers
19class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
20{
21public:
22 enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
23 TimerBase(Unit unit, bool stuckAtZero)
24 : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false)
25 , m_start(0), m_last(0) {}
26
27 virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0
28 virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds
29
30 void StartTimer();
31 double ElapsedTimeAsDouble();
32 unsigned long ElapsedTime();
33
34private:
35 double ConvertTo(TimerWord t, Unit unit);
36
37 Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
38 bool m_stuckAtZero, m_started;
39 TimerWord m_start, m_last;
40};
41
42/// \brief Measure CPU time spent executing instructions of this thread (if supported by OS)
43/// \note ThreadUserTimer only works correctly on Windows NT or later desktops and servers.
44/// On Unix-based it reports process time. On Windows Phone and Windows Store it reports wall
45/// clock time with performance counter precision. On all others it reports wall clock time.
47{
48public:
49 ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
50 TimerWord GetCurrentTimerValue();
51 TimerWord TicksPerSecond();
52};
53
54/// high resolution timer
55class CRYPTOPP_DLL Timer : public TimerBase
56{
57public:
58 Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
59 TimerWord GetCurrentTimerValue();
60 TimerWord TicksPerSecond();
61};
62
63NAMESPACE_END
64
65#endif
Measure CPU time spent executing instructions of this thread (if supported by OS)
Definition: hrtimer.h:47
Base class for timers.
Definition: hrtimer.h:20
high resolution timer
Definition: hrtimer.h:56
Library configuration file.
Crypto++ library namespace.