ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cppunit_timer.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006
00003  * Francois Dumont
00004  *
00005  * This material is provided "as is", with absolutely no warranty expressed
00006  * or implied. Any use is at your own risk.
00007  *
00008  * Permission to use or copy this software for any purpose is hereby granted
00009  * without fee, provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  *
00014  */
00015 
00016 #ifndef CPPUNIT_TIMER_H
00017 #define CPPUNIT_TIMER_H
00018 
00019 #if defined (_WIN32)
00020 #  define CPPUNIT_WIN32_TIMER
00021 #  include <windows.h>
00022 #endif
00023 
00024 class Timer {
00025 public:
00026   Timer() {
00027 #if defined (CPPUNIT_WIN32_TIMER)
00028     m_start.LowPart = m_restart.LowPart = m_stop.LowPart = 0;
00029     m_start.HighPart = m_restart.HighPart = m_stop.HighPart = 0;
00030     QueryPerformanceFrequency(&m_frequency);
00031 #endif
00032   }
00033 
00034   void start() {
00035 #if defined (CPPUNIT_WIN32_TIMER)
00036     QueryPerformanceCounter(&m_start);
00037 #endif
00038   }
00039 
00040   void restart() {
00041 #if defined (CPPUNIT_WIN32_TIMER)
00042     QueryPerformanceCounter(&m_restart);
00043     if (m_start.HighPart == 0 && m_start.LowPart == 0) {
00044       m_start = m_restart;
00045     }
00046 #endif
00047   }
00048 
00049   void stop() {
00050 #if defined (CPPUNIT_WIN32_TIMER)
00051     LARGE_INTEGER stop;
00052     QueryPerformanceCounter(&stop);
00053     if ((m_stop.HighPart != 0 || m_stop.LowPart != 0) &&
00054         m_restart.HighPart != 0 && m_restart.LowPart != 0) {
00055       m_stop.HighPart += (stop.HighPart - m_restart.HighPart);
00056       if (stop.LowPart < m_restart.LowPart) {
00057         if (m_restart.LowPart - stop.LowPart > m_stop.LowPart) {
00058           m_stop.HighPart -= 1;
00059         }
00060         m_stop.LowPart -= m_restart.LowPart - stop.LowPart;
00061       }
00062       else {
00063         if (stop.LowPart - m_restart.LowPart > 0xFFFFFFFF - m_stop.LowPart) {
00064           m_stop.HighPart += 1;
00065         }
00066         m_stop.LowPart += stop.LowPart - m_restart.LowPart;
00067       }
00068     }
00069     else {
00070       m_stop = stop;
00071     }
00072 #endif
00073   }
00074 
00075   double elapsedMilliseconds() const {
00076 #if defined (CPPUNIT_WIN32_TIMER)
00077     LARGE_INTEGER elapsed;
00078     elapsed.HighPart = m_stop.HighPart - m_start.HighPart;
00079     elapsed.LowPart = m_stop.LowPart - m_start.LowPart;
00080     return (double)elapsed.QuadPart / (double)m_frequency.QuadPart * 1000;
00081 #else
00082     return 0;
00083 #endif
00084   }
00085 
00086   static bool supported() {
00087 #if defined (CPPUNIT_WIN32_TIMER)
00088     return true;
00089 #else
00090     return false;
00091 #endif
00092   }
00093 
00094 private:
00095 #if defined (CPPUNIT_WIN32_TIMER)
00096   LARGE_INTEGER m_frequency;
00097   LARGE_INTEGER m_start, m_stop, m_restart;
00098 #endif
00099 };
00100 
00101 #endif

Generated on Sat May 26 2012 04:34:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.