Cantera  2.3.0
clockWC.cpp
Go to the documentation of this file.
1 /**
2  * @file clockWC.cpp
3  * Definitions 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 #include <time.h>
11 #include "cantera/base/clockWC.h"
12 
13 namespace Cantera
14 {
16  last_num_ticks(clock()),
17  clock_rollovers(0u),
18  start_ticks(0),
19  inv_clocks_per_sec(1./(double)CLOCKS_PER_SEC),
20  clock_width((double)(1L<<((int)sizeof(clock_t)*8-2))*4./(double)CLOCKS_PER_SEC)
21 {
23 }
24 
26 {
27  start_ticks = last_num_ticks = clock();
28  clock_rollovers = 0u;
29  return 0.0;
30 }
31 
33 {
34  clock_t num_ticks = clock();
35  if (num_ticks < last_num_ticks) {
37  }
38  double value = (num_ticks - start_ticks) * inv_clocks_per_sec;
39  if (clock_rollovers) {
40  value += clock_rollovers * clock_width;
41  }
42  last_num_ticks = num_ticks;
43  return value;
44 }
45 }
clockWC()
Constructor.
Definition: clockWC.cpp:15
Declarations for a simple class that implements an Ansi C wall clock timer (see Cantera::clockWC).
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
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: application.cpp:29
double start()
Resets the internal counters and returns the wall clock time in seconds.
Definition: clockWC.cpp:25