- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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