Cantera  2.1.2
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  /*!
66  * Returns system cpu and wall clock time in seconds. This is a strictly
67  * Ansi C timer, since clock() is defined as an Ansi C function. On some
68  * machines clock() returns type unsigned long (HP) and on others (SUN)
69  * it returns type long. An attempt to recover the actual time for clocks
70  * which have rolled over is made also. However, it only works if this
71  * function is called fairly regularily during the solution procedure.
72  */
73  double secondsWC();
74 
75 private:
76  //! Counters the value of the number of ticks from the last call.
77  clock_t last_num_ticks;
78 
79  //! Number of clock rollovers since the last initialization
80  /*!
81  * The clock will rollover if the calculation is long enough.
82  * This object senses that by seeing if the raw tick counter is
83  * has decreased from the last time.
84  */
85  unsigned int clock_rollovers;
86 
87  //! Counter containing the value of the number of ticks from
88  //! the first call (or the reset call).
89  clock_t start_ticks;
90 
91  //! internal constant containing clock ticks per second
92  const double inv_clocks_per_sec;
93 
94  //! internal constant containing the total number of ticks
95  //! per rollover.
96  const double clock_width;
97 };
98 }
99 #endif
clockWC()
Constructor.
Definition: clockWC.cpp:18
const double inv_clocks_per_sec
internal constant containing clock ticks per second
Definition: clockWC.h:92
unsigned int clock_rollovers
Number of clock rollovers since the last initialization.
Definition: clockWC.h:85
The class provides the wall clock timer in seconds.
Definition: clockWC.h:51
double secondsWC()
Returns the wall clock time in seconds since the last reset.
Definition: clockWC.cpp:35
clock_t last_num_ticks
Counters the value of the number of ticks from the last call.
Definition: clockWC.h:77
clock_t start_ticks
Counter containing the value of the number of ticks from the first call (or the reset call)...
Definition: clockWC.h:89
const double clock_width
internal constant containing the total number of ticks per rollover.
Definition: clockWC.h:96
double start()
Resets the internal counters and returns the wall clock time in seconds.
Definition: clockWC.cpp:28