Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. #ifndef CRYPTOPP_HRTIMER_H
  2. #define CRYPTOPP_HRTIMER_H
  3. #include "config.h"
  4. #ifndef HIGHRES_TIMER_AVAILABLE
  5. #include <time.h>
  6. #endif
  7. NAMESPACE_BEGIN(CryptoPP)
  8. #ifdef HIGHRES_TIMER_AVAILABLE
  9. typedef word64 TimerWord;
  10. #else
  11. typedef clock_t TimerWord;
  12. #endif
  13. //! _
  14. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase
  15. {
  16. public:
  17. enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS};
  18. TimerBase(Unit unit, bool stuckAtZero) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {}
  19. virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0
  20. virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds
  21. void StartTimer();
  22. double ElapsedTimeAsDouble();
  23. unsigned long ElapsedTime();
  24. private:
  25. double ConvertTo(TimerWord t, Unit unit);
  26. Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX
  27. bool m_stuckAtZero, m_started;
  28. TimerWord m_start, m_last;
  29. };
  30. //! measure CPU time spent executing instructions of this thread (if supported by OS)
  31. /*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and others wall clock time.
  32. */
  33. class ThreadUserTimer : public TimerBase
  34. {
  35. public:
  36. ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
  37. TimerWord GetCurrentTimerValue();
  38. TimerWord TicksPerSecond();
  39. };
  40. //! high resolution timer
  41. class CRYPTOPP_DLL Timer : public TimerBase
  42. {
  43. public:
  44. Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {}
  45. TimerWord GetCurrentTimerValue();
  46. TimerWord TicksPerSecond();
  47. };
  48. NAMESPACE_END
  49. #endif