- Main Page
- Namespaces
- Classes
- Files

# hrtimer.h

    00001 #ifndef CRYPTOPP_HRTIMER_H
    00002 #define CRYPTOPP_HRTIMER_H
    00003
    00004 #include "config.h"
    00005 #ifndef HIGHRES_TIMER_AVAILABLE
    00006 #include <time.h>
    00007 #endif
    00008
    00009 NAMESPACE_BEGIN(CryptoPP)
    00010
    00011 #ifdef HIGHRES_TIMER_AVAILABLE
    00012         typedef word64 TimerWord;
    00013 #else
    00014         typedef clock_t TimerWord;
    00015 #endif
    00016
    00017 //! _
    00018 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
    00019 {
    00020 public:
    00021         enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
    00022         TimerBase(Unit unit, bool stuckAtZero)  : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {}
    00023
    00024         virtual TimerWord GetCurrentTimerValue() =0;    // GetCurrentTime is a macro in MSVC 6.0
    00025         virtual TimerWord TicksPerSecond() =0;  // this is not the resolution, just a conversion factor into seconds
    00026
    00027         void StartTimer();
    00028         double ElapsedTimeAsDouble();
    00029         unsigned long ElapsedTime();
    00030
    00031 private:
    00032         double ConvertTo(TimerWord t, Unit unit);
    00033
    00034         Unit m_timerUnit;       // HPUX workaround: m_unit is a system macro on HPUX
    00035         bool m_stuckAtZero, m_started;
    00036         TimerWord m_start, m_last;
    00037 };
    00038
    00039 //! measure CPU time spent executing instructions of this thread (if supported by OS)
    00040 /*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and others wall clock time.
    00041 */
    00042 class ThreadUserTimer : public TimerBase
    00043 {
    00044 public:
    00045         ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false)       : TimerBase(unit, stuckAtZero) {}
    00046         TimerWord GetCurrentTimerValue();
    00047         TimerWord TicksPerSecond();
    00048 };
    00049
    00050 //! high resolution timer
    00051 class CRYPTOPP_DLL Timer : public TimerBase
    00052 {
    00053 public:
    00054         Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
    00055         TimerWord GetCurrentTimerValue();
    00056         TimerWord TicksPerSecond();
    00057 };
    00058
    00059 NAMESPACE_END
    00060
    00061 #endif