hrtimer.h

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

Generated on Fri Dec 16 03:04:16 2005 for Crypto++ by  doxygen 1.4.5