Carmen Code
 All Classes Files Functions Variables Macros Pages
Public Member Functions | List of all members
Timer Class Reference

An object Timer gives information on the CPU time of long-time computations. More...

#include <Timer.h>

Public Member Functions

 Timer ()
 Constructor of Timer class. Initialize timer. More...
 
void resetStart ()
 Resets time and start. More...
 
void check ()
 Adds CPU time and real time to their buffers and resets. For long computations, it is recommended to do this operation at least once per iteration. More...
 
void start ()
 Starts timer. More...
 
double stop ()
 Stop timer and, if asked, returns CPU time from previous start in seconds. More...
 
double CPUTime ()
 Returns CPU time from previous start in seconds. More...
 
double realTime ()
 Returns real time from previous start in seconds. More...
 
void add (double cpuTime, double realTime)
 Adds time to buffer (only when a computation is restarted). More...
 

Detailed Description

An object Timer gives information on the CPU time of long-time computations.

Constructor & Destructor Documentation

Timer::Timer ( )

Constructor of Timer class. Initialize timer.

31 {
32  StartCPUTime = clock();
33  time(&StartRealTime);
34 
35  sumCPUtime = 0.;
36  sumRealtime = 0.;
37  TimerOn = true;
38 }

Member Function Documentation

void Timer::add ( double  cpuTime,
double  realTime 
)

Adds time to buffer (only when a computation is restarted).

Parameters
cpuTimeCPU time
realTimeReal time
Returns
void
174 {
175  sumCPUtime=cpuTime;
176  sumRealtime=realTime;
177 }
double realTime()
Returns real time from previous start in seconds.
Definition: Timer.cpp:148
void Timer::check ( )

Adds CPU time and real time to their buffers and resets. For long computations, it is recommended to do this operation at least once per iteration.

Returns
void
104 {
105  // --- Local variables ---
106 
107  clock_t EndCPUTime; // end CPU time
108 
109  // --- Execution ---
110 
111  EndCPUTime = clock();
112  sumCPUtime += double((unsigned long int)EndCPUTime-StartCPUTime)/ (unsigned long int)CLOCKS_PER_SEC;
113  StartCPUTime = EndCPUTime;
114 
115 }

Here is the caller graph for this function:

double Timer::CPUTime ( )

Returns CPU time from previous start in seconds.

Returns
double
125 {
126  // --- Local variables ---
127  clock_t EndCPUTime;
128 
129  // --- Execution ---
130  if (TimerOn)
131  {
132  // If timer is running, compute and return time in seconds
133  EndCPUTime = clock();
134  return sumCPUtime+double((unsigned long int)EndCPUTime-StartCPUTime)/ (unsigned long int)CLOCKS_PER_SEC;
135  }
136  else
137  // else return time previously computed between last start and stop procedures
138  return sumCPUtime;
139 }

Here is the caller graph for this function:

double Timer::realTime ( )

Returns real time from previous start in seconds.

Returns
double
149 {
150  // --- Local variables ---
151 
152  time_t EndRealTime;
153 
154  // --- Execution ---
155 
156  if (TimerOn)
157  {
158  // If timer is running, compute and return time in seconds
159  time(&EndRealTime);
160  return sumRealtime+difftime(EndRealTime,StartRealTime);
161  }
162  else
163  // else return time previously computed between last start and stop procedures
164  return sumRealtime;
165 }

Here is the caller graph for this function:

void Timer::resetStart ( )

Resets time and start.

Returns
void
47 {
48  StartCPUTime = clock();
49  time(&StartRealTime);
50 
51  sumCPUtime = 0.;
52  sumRealtime = 0.;
53  TimerOn = true;
54 }
void Timer::start ( )

Starts timer.

Returns
void
63 {
64  StartCPUTime = clock();
65  time(&StartRealTime);
66 
67  TimerOn = true;
68  return;
69 }

Here is the caller graph for this function:

double Timer::stop ( )

Stop timer and, if asked, returns CPU time from previous start in seconds.

Returns
double
78 {
79  // --- Local variables ---
80 
81  clock_t EndCPUTime; // end CPU time
82  time_t EndRealTime; // end real time
83 
84 
85  // --- Execution ---
86 
87  EndCPUTime = clock();
88  time(&EndRealTime);
89 
90  sumCPUtime += double((unsigned long int)EndCPUTime-StartCPUTime)/ (unsigned long int)CLOCKS_PER_SEC;
91  sumRealtime += difftime(EndRealTime,StartRealTime);
92 
93  TimerOn = false;
94  return sumCPUtime;
95 }

Here is the caller graph for this function:


The documentation for this class was generated from the following files: