Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: C++  |  size: 0.62 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifndef TIMER_H
  2. #define TIMER_H
  3.  
  4. #include <windows.h>
  5.  
  6. class Timer
  7. {
  8. private:
  9.         __int64 initialTS, currentTS;
  10.         float secsPerCount;
  11.  
  12. public:
  13.         Timer()
  14.         {
  15.                 __int64 countsPerSec = initialTS = currentTS = 0;
  16.                 QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
  17.                 if (countsPerSec == 0)
  18.                         secsPerCount = 1.0f;
  19.                 else
  20.                         secsPerCount = 1.0f / (float)countsPerSec;
  21.                 init();
  22.         }
  23.         void init()
  24.         {
  25.                 QueryPerformanceCounter((LARGE_INTEGER*)&initialTS);
  26.         }
  27.         float diff()
  28.         {
  29.                 QueryPerformanceCounter((LARGE_INTEGER*)&currentTS);
  30.                 return ((float)currentTS - (float)initialTS)*secsPerCount;
  31.         }
  32. };
  33.  
  34. #endif