clockWC.h

Go to the documentation of this file.
00001 /**
00002  * @file clockWC.h
00003  *    Declarations for a simple class that implements an Ansi C wall clock timer
00004  *   (see \ref Cantera::clockWC).
00005  */
00006 /*
00007  * $Author: hkmoffa $
00008  * $Revision: 368 $
00009  * $Date: 2010-01-03 19:46:26 -0500 (Sun, 03 Jan 2010) $
00010  */
00011 /*
00012  * Copywrite 2004 Sandia Corporation. Under the terms of Contract
00013  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00014  * retains certain rights in this software.
00015  * See file License.txt for licensing information.
00016  */
00017 
00018 #ifndef CT_CLOCKWC_H
00019 #define CT_CLOCKWC_H
00020 
00021 #include <time.h>
00022 namespace Cantera {
00023 
00024   //! The class provides the wall clock timer in seconds
00025   /*!
00026    *  This routine relies on the ANSI C routine, clock(), for
00027    *  its basic operation. Therefore, it should be fairly 
00028    *  portable.
00029    * 
00030    * The clock will rollover if the calculation is long enough.
00031    * The wraparound time is roughly 72 minutes for a 32 bit system.
00032    * This object senses that by seeing if the raw tick counter is
00033    * has decreased from the last time. If it senses a wraparound has
00034    * occurred, it increments an internal counter to account for this.
00035    * Therefore, for long calculations, this object must be called
00036    * at regular intervals for the seconds timer to be accurate.
00037    *
00038    * An example of how to use the timer is given below. timeToDoCalcs
00039    * countains the wall clock time calculated for the operation.
00040    * 
00041    *
00042    *  @code
00043    *   clockWC wc;
00044    *   do_hefty_calculations_atLeastgreaterThanAMillisecond();
00045    *   double timeToDoCalcs = wc.secondsWC();
00046    *  @endcode
00047    *
00048    *  In general, the process to be timed must take more than a millisecond
00049    *  for this clock to enough of a significant resolution to be
00050    *  accurate.
00051    *
00052    * @ingroup globalUtilFuncs
00053    *
00054    */
00055   class clockWC {
00056   public:
00057     //! Constructor
00058     /*!
00059      * This also serves to initialize the ticks within the object
00060      */
00061     clockWC();
00062     
00063     //! Resets the internal counters and returns the wall clock time
00064     //! in seconds
00065     double start();
00066 
00067     //! Returns the wall clock time in seconds since the last reset.
00068     double secondsWC();
00069 
00070   private: 
00071     //! Counters the value of the number of ticks from the last call.
00072     clock_t last_num_ticks;
00073 
00074     //! Number of clock rollovers since the last initialization
00075     /*!
00076      * The clock will rollover if the calculation is long enough.
00077      * This object senses that by seeing if the raw tick counter is
00078      * has decreased from the last time.
00079      */
00080     unsigned int clock_rollovers;
00081 
00082     //! Counter countaining the value of the number of ticks from
00083     //! the first call (or the reset call).
00084     clock_t start_ticks;
00085 
00086     //! internal constant containing clock ticks per second
00087     const  double  inv_clocks_per_sec;
00088 
00089     //! internal constant containing the total number of ticks
00090     //! per rollover.
00091     const  double  clock_width;
00092   };
00093 }
00094 #endif
Generated by  doxygen 1.6.3