Cantera  2.4.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 // This file is part of Cantera. See License.txt in the top-level directory or
8 // at http://www.cantera.org/license.txt for license and copyright information.
9 
10 #ifndef CT_CLOCKWC_H
11 #define CT_CLOCKWC_H
12 
13 #include <time.h>
14 namespace Cantera
15 {
16 
17 //! The class provides the wall clock timer in seconds
18 /*!
19  * This routine relies on the ANSI C routine, clock(), for its basic operation.
20  * Therefore, it should be fairly portable.
21  *
22  * The clock will rollover if the calculation is long enough. The wraparound
23  * time is roughly 72 minutes for a 32 bit system. This object senses that by
24  * seeing if the raw tick counter is has decreased from the last time. If it
25  * senses a wraparound has occurred, it increments an internal counter to
26  * account for this. Therefore, for long calculations, this object must be
27  * called at regular intervals for the seconds timer to be accurate.
28  *
29  * An example of how to use the timer is given below. timeToDoCalcs contains the
30  * wall clock time calculated for the operation.
31  *
32  * @code
33  * clockWC wc;
34  * do_hefty_calculations_atLeastgreaterThanAMillisecond();
35  * double timeToDoCalcs = wc.secondsWC();
36  * @endcode
37  *
38  * In general, the process to be timed must take more than a millisecond for
39  * this clock to enough of a significant resolution to be accurate.
40  *
41  * @ingroup globalUtilFuncs
42  *
43  */
44 class clockWC
45 {
46 public:
47  //! Constructor
48  /*!
49  * This also serves to initialize the ticks within the object
50  */
51  clockWC();
52 
53  //! Resets the internal counters and returns the wall clock time in seconds
54  double start();
55 
56  //! Returns the wall clock time in seconds since the last reset.
57  /*!
58  * Returns system cpu and wall clock time in seconds. This is a strictly
59  * Ansi C timer, since clock() is defined as an Ansi C function. On some
60  * machines clock() returns type unsigned long (HP) and on others (SUN)
61  * it returns type long. An attempt to recover the actual time for clocks
62  * which have rolled over is made also. However, it only works if this
63  * function is called fairly regularily during the solution procedure.
64  */
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. This object
74  * senses that by seeing if the raw tick counter is has decreased from the
75  * last time.
76  */
77  unsigned int clock_rollovers;
78 
79  //! Counter containing the value of the number of ticks from the first call
80  //! (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 per rollover.
87  const double clock_width;
88 };
89 }
90 #endif
clockWC()
Constructor.
Definition: clockWC.cpp:15
const double inv_clocks_per_sec
internal constant containing clock ticks per second
Definition: clockWC.h:84
unsigned int clock_rollovers
Number of clock rollovers since the last initialization.
Definition: clockWC.h:77
The class provides the wall clock timer in seconds.
Definition: clockWC.h:44
double secondsWC()
Returns the wall clock time in seconds since the last reset.
Definition: clockWC.cpp:32
clock_t last_num_ticks
Counters the value of the number of ticks from the last call.
Definition: clockWC.h:69
clock_t start_ticks
Counter containing the value of the number of ticks from the first call (or the reset call)...
Definition: clockWC.h:81
const double clock_width
internal constant containing the total number of ticks per rollover.
Definition: clockWC.h:87
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
double start()
Resets the internal counters and returns the wall clock time in seconds.
Definition: clockWC.cpp:25