Cantera  2.1.2
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  * 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 #include <time.h>
14 #include "cantera/base/clockWC.h"
15 
16 namespace Cantera
17 {
19  last_num_ticks(clock()),
20  clock_rollovers(0u),
21  start_ticks(0),
22  inv_clocks_per_sec(1./(double)CLOCKS_PER_SEC),
23  clock_width((double)(1L<<((int)sizeof(clock_t)*8-2))*4./(double)CLOCKS_PER_SEC)
24 {
26 }
27 
29 {
30  start_ticks = last_num_ticks = clock();
31  clock_rollovers = 0u;
32  return 0.0;
33 }
34 
36 {
37  clock_t num_ticks = clock();
38  if (num_ticks < last_num_ticks) {
40  }
41  double value = (num_ticks - start_ticks) * inv_clocks_per_sec;
42  if (clock_rollovers) {
43  value += clock_rollovers * clock_width;
44  }
45  last_num_ticks = num_ticks;
46  return value;
47 }
48 }
clockWC()
Constructor.
Definition: clockWC.cpp:18
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:92
unsigned int clock_rollovers
Number of clock rollovers since the last initialization.
Definition: clockWC.h:85
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