home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / timer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  1.6 KB  |  49 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : timer.h                                                             //
  12. //  Description: High-precision timer using Intel clock cycle count                  //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. #pragma warning(disable : 4035)
  17.  
  18. inline unsigned __int64 GetCycleCount(void)
  19. {
  20.     _asm    _emit 0x0F
  21.     _asm    _emit 0x31
  22. }
  23.  
  24. class KTimer
  25. {
  26.     unsigned __int64  m_startcycle;
  27.  
  28. public:
  29.  
  30.     unsigned __int64  m_overhead;
  31.  
  32.     KTimer(void)
  33.     {
  34.         m_overhead = 0;
  35.         Start();
  36.         m_overhead = Stop();
  37.     }
  38.     
  39.     void Start(void)
  40.     {
  41.         m_startcycle = GetCycleCount();
  42.     }
  43.  
  44.     unsigned __int64 Stop(void)
  45.     {
  46.         return GetCycleCount()-m_startcycle-m_overhead;
  47.     }
  48. };
  49.