Guest User

Untitled

a guest
Jul 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. class HRTimer {
  2. public:
  3.     HRTimer(void) {
  4.         frequency = this->GetFrequency();
  5.     }
  6.     LARGE_INTEGER getFrequency() {
  7.         LARGE_INTEGER proc_freq;
  8.         QueryPerformanceFrequency(&proc_freq);
  9.         return proc_freq.QuadPart;
  10.     }
  11.     void startTimer() {
  12.         DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);
  13.         ::QueryPerformanceCounter(&start);
  14.         ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
  15.     }
  16.     double stopTimer() {
  17.         DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);
  18.         ::QueryPerformanceCounter(&stop);
  19.         ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
  20.         return ((stop.QuadPart - start.QuadPart) / (double)frequency);
  21.     }
  22. private:
  23.     LARGE_INTEGER start;
  24.     LARGE_INTEGER stop;
  25.     LARGE_INTEGER frequency;
  26. }
Add Comment
Please, Sign In to add comment