From bfbe78e6952e99e7406af3bfede277d8292eb819 Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 8 Apr 2004 01:23:05 +0000 Subject: add ThreadUserTimer git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@153 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- hrtimer.h | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'hrtimer.h') diff --git a/hrtimer.h b/hrtimer.h index 1e51392..3b74b01 100644 --- a/hrtimer.h +++ b/hrtimer.h @@ -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 -- cgit v1.2.1