Timer.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_TIMING_TIMER_H_
36 #define _BLAZE_UTIL_TIMING_TIMER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <limits>
44 #include <blaze/util/Time.h>
45 #include <blaze/util/Types.h>
46 
47 
48 namespace blaze {
49 
50 namespace timing {
51 
52 //=================================================================================================
53 //
54 // CLASS DEFINITION
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
102 template< typename TP > // Timing policy
103 class Timer
104 {
105  public:
106  //**Type definitions****************************************************************************
107  typedef TP TimingPolicy;
108  //**********************************************************************************************
109 
110  //**Constructor*********************************************************************************
113  explicit inline Timer();
115  //**********************************************************************************************
116 
117  //**Destructor**********************************************************************************
118  // No explicitly declared destructor.
119  //**********************************************************************************************
120 
121  //**Timing functions****************************************************************************
124  inline void start();
125  inline void end ();
126  inline void reset();
128  //**********************************************************************************************
129 
130  //**Get functions*******************************************************************************
133  inline size_t getCounter() const;
135  //**********************************************************************************************
136 
137  //**Time evaluation functions*******************************************************************
140  inline double total() const;
141  inline double average() const;
142  inline double min() const;
143  inline double max() const;
144  inline double last() const;
146  //**********************************************************************************************
147 
148  private:
149  size_t counter_;
150  double start_;
151  double end_;
152  double time_;
153  double min_;
154  double max_;
155  double last_;
156 };
157 //*************************************************************************************************
158 
159 
160 
161 
162 //=================================================================================================
163 //
164 // CONSTRUCTOR
165 //
166 //=================================================================================================
167 
168 //*************************************************************************************************
175 template< typename TP > // Timing policy
177  : counter_( 0 )
178  , start_ ( 0.0 )
179  , end_ ( 0.0 )
180  , time_ ( 0.0 )
181  , min_ ( std::numeric_limits<double>::max() )
182  , max_ ( 0.0 )
183  , last_ ( 0.0 )
184 {
185  // Starting the time measurement
186  start();
187 }
188 //*************************************************************************************************
189 
190 
191 
192 
193 //=================================================================================================
194 //
195 // TIMING FUNCTIONS
196 //
197 //=================================================================================================
198 
199 //*************************************************************************************************
206 template< typename TP > // Timing policy
207 inline void Timer<TP>::start()
208 {
209  // Starting the time measurement and calculating a time stamp
210  start_ = TimingPolicy::getTimestamp();
211 }
212 //*************************************************************************************************
213 
214 
215 //*************************************************************************************************
223 template< typename TP > // Timing policy
224 inline void Timer<TP>::end()
225 {
226  // Stopping the time measurement and calculating a time stamp
227  end_ = TimingPolicy::getTimestamp();
228 
229  // Increasing the counter
230  ++counter_;
231 
232  // Calculating the wallclock and CPU time
233  const double diff( end_ - start_ );
234 
235  // Average time measurement
236  time_ += diff;
237 
238  // Minimum time measurement
239  if( diff < min_ ) min_ = diff;
240 
241  // Maximum time measurement
242  if( diff > max_ ) max_ = diff;
243 
244  // Last time measurement
245  last_ = diff;
246 }
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
259 template< typename TP > // Timing policy
260 inline void Timer<TP>::reset()
261 {
262  counter_ = 0;
263  start_ = 0.0;
264  end_ = 0.0;
265  time_ = 0.0;
267  max_ = 0.0;
268  last_ = 0.0;
269 }
270 //*************************************************************************************************
271 
272 
273 
274 
275 //=================================================================================================
276 //
277 // GET FUNCTIONS
278 //
279 //=================================================================================================
280 
281 //*************************************************************************************************
286 template< typename TP > // Timing policy
287 inline size_t Timer<TP>::getCounter() const
288 {
289  return counter_;
290 }
291 //*************************************************************************************************
292 
293 
294 
295 
296 //=================================================================================================
297 //
298 // TIME EVALUATION FUNCTIONS
299 //
300 //=================================================================================================
301 
302 //*************************************************************************************************
307 template< typename TP > // Timing policy
308 inline double Timer<TP>::total() const
309 {
310  return time_;
311 }
312 //*************************************************************************************************
313 
314 
315 //*************************************************************************************************
320 template< typename TP > // Timing policy
321 inline double Timer<TP>::average() const
322 {
323  return time_ / counter_;
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
333 template< typename TP > // Timing policy
334 inline double Timer<TP>::min() const
335 {
336  return min_;
337 }
338 //*************************************************************************************************
339 
340 
341 //*************************************************************************************************
346 template< typename TP > // Timing policy
347 inline double Timer<TP>::max() const
348 {
349  return max_;
350 }
351 //*************************************************************************************************
352 
353 
354 //*************************************************************************************************
359 template< typename TP > // Timing policy
360 inline double Timer<TP>::last() const
361 {
362  return last_;
363 }
364 //*************************************************************************************************
365 
366 } // timing
367 
368 } // blaze
369 
370 #endif
Header file for basic type definitions.
double last_
The last measured time.
Definition: Timer.h:155
double max_
The maximal time of all measurements.
Definition: Timer.h:154
Header file for time functions.
STL namespace.
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1716
double total() const
Returns the total elapsed time of all performed time measurements.
Definition: Timer.h:308
double max() const
Returns the maximal time of all performed time measurements.
Definition: Timer.h:347
double start_
Start of the current time measurement.
Definition: Timer.h:150
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2809
double end_
End of the current time measurement.
Definition: Timer.h:151
double last() const
Returns the last measured time.
Definition: Timer.h:360
void reset()
Resetting the timer.
Definition: Timer.h:260
TP TimingPolicy
Timing policy of the Timer.
Definition: Timer.h:107
double min() const
Returns the minimal time of all performed time measurements.
Definition: Timer.h:334
double min_
The minimal time of all measurements.
Definition: Timer.h:153
void end()
Ending a single time measurement.
Definition: Timer.h:224
size_t counter_
Number of performed time measurements.
Definition: Timer.h:149
double average() const
Returns the average time of all performed time measurements.
Definition: Timer.h:321
void start()
Starting a single time measurement.
Definition: Timer.h:207
size_t getCounter() const
Returns the total number of time measurements performed by this timer.
Definition: Timer.h:287
Timer()
Constructor of the Timer class.
Definition: Timer.h:176
double time_
The total elapsed time of all measurements.
Definition: Timer.h:152
Progress timer for time and performance measurements.The Timer class offers timing & benchmarking fun...
Definition: Timer.h:103