source: git/src-cryptopp/hrtimer.h

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 2.0 KB
Line 
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//! \class TimerBase
19//! \brief Base class for timers
20class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
21{
22public:
23        enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
24        TimerBase(Unit unit, bool stuckAtZero)
25                : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false)
26                , m_start(0), m_last(0) {}
27
28        virtual TimerWord GetCurrentTimerValue() =0;    // GetCurrentTime is a macro in MSVC 6.0
29        virtual TimerWord TicksPerSecond() =0;  // this is not the resolution, just a conversion factor into seconds
30
31        void StartTimer();
32        double ElapsedTimeAsDouble();
33        unsigned long ElapsedTime();
34
35private:
36        double ConvertTo(TimerWord t, Unit unit);
37
38        Unit m_timerUnit;       // HPUX workaround: m_unit is a system macro on HPUX
39        bool m_stuckAtZero, m_started;
40        TimerWord m_start, m_last;
41};
42
43//! \class ThreadUserTimer
44//! \brief Measure CPU time spent executing instructions of this thread (if supported by OS)
45//! \note ThreadUserTimer only works correctly on Windows NT or later desktops and servers.
46//! On Unix-based it reports process time. On Windows Phone and Windows Store it reports wall
47//! clock time with performance counter precision. On all others it reports wall clock time.
48class ThreadUserTimer : public TimerBase
49{
50public:
51        ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
52        TimerWord GetCurrentTimerValue();
53        TimerWord TicksPerSecond();
54};
55
56//! high resolution timer
57class CRYPTOPP_DLL Timer : public TimerBase
58{
59public:
60        Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
61        TimerWord GetCurrentTimerValue();
62        TimerWord TicksPerSecond();
63};
64
65NAMESPACE_END
66
67#endif
Note: See TracBrowser for help on using the repository browser.