diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2004-04-08 01:23:05 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2004-04-08 01:23:05 +0000 |
commit | bfbe78e6952e99e7406af3bfede277d8292eb819 (patch) | |
tree | f5f03d5c62ba495a5a59513eb4c40980216ca56d /hrtimer.h | |
parent | 1c501761103d21d7c6c186cd0f807e6c6aee6fad (diff) | |
download | cryptopp-bfbe78e6952e99e7406af3bfede277d8292eb819.tar.gz |
add ThreadUserTimer
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@153 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'hrtimer.h')
-rw-r--r-- | hrtimer.h | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -7,28 +7,47 @@ NAMESPACE_BEGIN(CryptoPP) #ifdef HIGHRES_TIMER_AVAILABLE -//! high resolution timer -class Timer +class TimerBase { public: enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS}; - Timer(Unit unit, bool stuckAtZero = false) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {} + TimerBase(Unit unit, bool stuckAtZero) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {} - static word64 GetCurrentTimerValue(); // GetCurrentTime is a macro in MSVC 6.0 - static word64 ConvertTo(word64 t, Unit unit); - // this is not the resolution, just a conversion factor into seconds - static word64 TicksPerSecond(); + virtual word64 GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0 + virtual word64 TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds void StartTimer(); - word64 ElapsedTimeInWord64(); + double ElapsedTimeAsDouble(); unsigned long ElapsedTime(); private: + double ConvertTo(word64 t, Unit unit); + Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX bool m_stuckAtZero, m_started; word64 m_start; }; +//! high resolution timer +class Timer : public TimerBase +{ +public: + Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} + word64 GetCurrentTimerValue(); + word64 TicksPerSecond(); +}; + +//! measure CPU time spent executing instructions of this thread (if supported by OS) +/*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and on Windows 98 wall clock time. +*/ +class ThreadUserTimer : public TimerBase +{ +public: + ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} + word64 GetCurrentTimerValue(); + word64 TicksPerSecond(); +}; + #endif NAMESPACE_END |