Cantera  2.0
clockWC.h
Go to the documentation of this file.
1 /**
2  * @file clockWC.h
3  * Declarations for a simple class that implements an Ansi C wall clock timer
4  * (see \ref Cantera::clockWC).
5  */
6 /*
7  * Copyright 2004 Sandia Corporation. Under the terms of Contract
8  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
9  * retains certain rights in this software.
10  * See file License.txt for licensing information.
11  */
12 
13 #ifndef CT_CLOCKWC_H
14 #define CT_CLOCKWC_H
15 
16 #include <time.h>
17 namespace Cantera
18 {
19 
20 //! The class provides the wall clock timer in seconds
21 /*!
22  * This routine relies on the ANSI C routine, clock(), for
23  * its basic operation. Therefore, it should be fairly
24  * portable.
25  *
26  * The clock will rollover if the calculation is long enough.
27  * The wraparound time is roughly 72 minutes for a 32 bit system.
28  * This object senses that by seeing if the raw tick counter is
29  * has decreased from the last time. If it senses a wraparound has
30  * occurred, it increments an internal counter to account for this.
31  * Therefore, for long calculations, this object must be called
32  * at regular intervals for the seconds timer to be accurate.
33  *
34  * An example of how to use the timer is given below. timeToDoCalcs
35  * contains the wall clock time calculated for the operation.
36  *
37  *
38  * @code
39  * clockWC wc;
40  * do_hefty_calculations_atLeastgreaterThanAMillisecond();
41  * double timeToDoCalcs = wc.secondsWC();
42  * @endcode
43  *
44  * In general, the process to be timed must take more than a millisecond
45  * for this clock to enough of a significant resolution to be
46  * accurate.
47  *
48  * @ingroup globalUtilFuncs
49  *
50  */
51 class clockWC
52 {
53 public:
54  //! Constructor
55  /*!
56  * This also serves to initialize the ticks within the object
57  */
58  clockWC();
59 
60  //! Resets the internal counters and returns the wall clock time
61  //! in seconds
62  double start();
63 
64  //! Returns the wall clock time in seconds since the last reset.
65  double secondsWC();
66 
67 private:
68  //! Counters the value of the number of ticks from the last call.
69  clock_t last_num_ticks;
70 
71  //! Number of clock rollovers since the last initialization
72  /*!
73  * The clock will rollover if the calculation is long enough.
74  * This object senses that by seeing if the raw tick counter is
75  * has decreased from the last time.
76  */
77  unsigned int clock_rollovers;
78 
79  //! Counter containing the value of the number of ticks from
80  //! the first call (or the reset call).
81  clock_t start_ticks;
82 
83  //! internal constant containing clock ticks per second
84  const double inv_clocks_per_sec;
85 
86  //! internal constant containing the total number of ticks
87  //! per rollover.
88  const double clock_width;
89 };
90 }
91 #endif