home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / bonus / demos / CS / exp / SOURCES / DEMO / TIMER.H < prev    next >
C/C++ Source or Header  |  2000-08-08  |  765b  |  41 lines

  1. #ifndef __PTIMER__
  2. #define __PTIMER__
  3. #include <windows.h>
  4.  
  5. class PTIMER
  6. {
  7.   __int64 freq;
  8.   double resolution;
  9.   __int64 start;
  10.   __int64 t;
  11. public:
  12.   PTIMER()
  13.     {
  14.       QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
  15.       QueryPerformanceCounter((LARGE_INTEGER*)&start);
  16.       resolution = 1.0/(double)freq;
  17.     }
  18.  
  19.   double time()
  20.     {
  21.       QueryPerformanceCounter((LARGE_INTEGER*)&t);
  22.       t = t-start;
  23.       return t*resolution;
  24.     }
  25.  
  26.   void reset(double te=0.0)
  27.     {
  28.       QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
  29.       QueryPerformanceCounter((LARGE_INTEGER*)&start);
  30.       resolution = 1.0/(double)freq;
  31.       start-=(__int64)(te*freq);
  32.     }
  33.  
  34.  
  35.   __int64 frequency()
  36.     { return freq;}
  37.  
  38. };
  39.  
  40. #endif
  41.