diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2002-10-04 17:31:41 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2002-10-04 17:31:41 +0000 |
commit | b21162cf8e06f40baa1f58be6a8c17435cebc34d (patch) | |
tree | 8b045309c238226c32a563b1df6b9c30a2f0e0b3 /hrtimer.h | |
download | cryptopp-b21162cf8e06f40baa1f58be6a8c17435cebc34d.tar.gz |
Initial revision
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@2 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'hrtimer.h')
-rw-r--r-- | hrtimer.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/hrtimer.h b/hrtimer.h new file mode 100644 index 0000000..81d9fcd --- /dev/null +++ b/hrtimer.h @@ -0,0 +1,43 @@ +#ifndef CRYPTOPP_HRTIMER_H +#define CRYPTOPP_HRTIMER_H + +#include "config.h" + +NAMESPACE_BEGIN(CryptoPP) + +#ifdef HIGHRES_TIMER_AVAILABLE + +//! high resolution timer +class Timer +{ +public: + enum Unit {SECONDS, MILLISECONDS, MICROSECONDS}; + Timer(Unit unit, bool stuckAtZero = false) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {} + + static word64 GetCurrentTimerValue(); // GetCurrentTime is a macro in MSVC 6.0 + static unsigned long ConvertTo(word64 t, Unit unit); + + // this is not the resolution, just a conversion factor into milliseconds + static inline unsigned int TicksPerMillisecond() + { +#if defined(CRYPTOPP_WIN32_AVAILABLE) + return 10000; +#elif defined(__unix__) || defined(macintosh) + return 1000; +#endif + } + + void StartTimer(); + unsigned long ElapsedTime(); + +private: + Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX + bool m_stuckAtZero, m_started; + word64 m_start; +}; + +#endif + +NAMESPACE_END + +#endif |