hrtimer.h

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

Generated on Sat Dec 23 02:07:07 2006 for Crypto++ by  doxygen 1.5.1-p1