Blaze 3.9
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
48namespace blaze {
49
50namespace timing {
51
52//=================================================================================================
53//
54// CLASS DEFINITION
55//
56//=================================================================================================
57
58//*************************************************************************************************
102template< typename TP > // Timing policy
103class Timer
104{
105 public:
106 //**Type definitions****************************************************************************
107 using TimingPolicy = TP;
108 //**********************************************************************************************
109
110 //**Constructors********************************************************************************
113 inline Timer();
115 //**********************************************************************************************
116
117 //**Timing functions****************************************************************************
120 inline void start();
121 inline void end ();
122 inline void reset();
124 //**********************************************************************************************
125
126 //**Get functions*******************************************************************************
129 inline size_t getCounter() const;
131 //**********************************************************************************************
132
133 //**Time evaluation functions*******************************************************************
136 inline double total() const;
137 inline double average() const;
138 inline double min() const;
139 inline double max() const;
140 inline double last() const;
142 //**********************************************************************************************
143
144 private:
145 size_t counter_;
146 double start_;
147 double end_;
148 double time_;
149 double min_;
150 double max_;
151 double last_;
152};
153//*************************************************************************************************
154
155
156
157
158//=================================================================================================
159//
160// CONSTRUCTORS
161//
162//=================================================================================================
163
164//*************************************************************************************************
171template< typename TP > // Timing policy
173 : counter_( 0 )
174 , start_ ( 0.0 )
175 , end_ ( 0.0 )
176 , time_ ( 0.0 )
177 , min_ ( std::numeric_limits<double>::max() )
178 , max_ ( 0.0 )
179 , last_ ( 0.0 )
180{
181 // Starting the time measurement
182 start();
183}
184//*************************************************************************************************
185
186
187
188
189//=================================================================================================
190//
191// TIMING FUNCTIONS
192//
193//=================================================================================================
194
195//*************************************************************************************************
202template< typename TP > // Timing policy
203inline void Timer<TP>::start()
204{
205 // Starting the time measurement and calculating a time stamp
206 start_ = TimingPolicy::getTimestamp();
207}
208//*************************************************************************************************
209
210
211//*************************************************************************************************
219template< typename TP > // Timing policy
220inline void Timer<TP>::end()
221{
222 // Stopping the time measurement and calculating a time stamp
223 end_ = TimingPolicy::getTimestamp();
224
225 // Increasing the counter
226 ++counter_;
227
228 // Calculating the wallclock and CPU time
229 const double diff( end_ - start_ );
230
231 // Average time measurement
232 time_ += diff;
233
234 // Minimum time measurement
235 if( diff < min_ ) min_ = diff;
236
237 // Maximum time measurement
238 if( diff > max_ ) max_ = diff;
239
240 // Last time measurement
241 last_ = diff;
242}
243//*************************************************************************************************
244
245
246//*************************************************************************************************
255template< typename TP > // Timing policy
256inline void Timer<TP>::reset()
257{
258 counter_ = 0;
259 start_ = 0.0;
260 end_ = 0.0;
261 time_ = 0.0;
263 max_ = 0.0;
264 last_ = 0.0;
265}
266//*************************************************************************************************
267
268
269
270
271//=================================================================================================
272//
273// GET FUNCTIONS
274//
275//=================================================================================================
276
277//*************************************************************************************************
282template< typename TP > // Timing policy
283inline size_t Timer<TP>::getCounter() const
284{
285 return counter_;
286}
287//*************************************************************************************************
288
289
290
291
292//=================================================================================================
293//
294// TIME EVALUATION FUNCTIONS
295//
296//=================================================================================================
297
298//*************************************************************************************************
303template< typename TP > // Timing policy
304inline double Timer<TP>::total() const
305{
306 return time_;
307}
308//*************************************************************************************************
309
310
311//*************************************************************************************************
316template< typename TP > // Timing policy
317inline double Timer<TP>::average() const
318{
319 return time_ / counter_;
320}
321//*************************************************************************************************
322
323
324//*************************************************************************************************
329template< typename TP > // Timing policy
330inline double Timer<TP>::min() const
331{
332 return min_;
333}
334//*************************************************************************************************
335
336
337//*************************************************************************************************
342template< typename TP > // Timing policy
343inline double Timer<TP>::max() const
344{
345 return max_;
346}
347//*************************************************************************************************
348
349
350//*************************************************************************************************
355template< typename TP > // Timing policy
356inline double Timer<TP>::last() const
357{
358 return last_;
359}
360//*************************************************************************************************
361
362} // timing
363
364} // blaze
365
366#endif
Header file for time functions.
Progress timer for time and performance measurements.
Definition: Timer.h:104
double end_
End of the current time measurement.
Definition: Timer.h:147
double max() const
Returns the maximal time of all performed time measurements.
Definition: Timer.h:343
TP TimingPolicy
Timing policy of the Timer.
Definition: Timer.h:107
double average() const
Returns the average time of all performed time measurements.
Definition: Timer.h:317
void end()
Ending a single time measurement.
Definition: Timer.h:220
double min() const
Returns the minimal time of all performed time measurements.
Definition: Timer.h:330
size_t getCounter() const
Returns the total number of time measurements performed by this timer.
Definition: Timer.h:283
double start_
Start of the current time measurement.
Definition: Timer.h:146
Timer()
Constructor of the Timer class.
Definition: Timer.h:172
double last_
The last measured time.
Definition: Timer.h:151
double time_
The total elapsed time of all measurements.
Definition: Timer.h:148
double min_
The minimal time of all measurements.
Definition: Timer.h:149
void reset()
Resetting the timer.
Definition: Timer.h:256
size_t counter_
Number of performed time measurements.
Definition: Timer.h:145
double last() const
Returns the last measured time.
Definition: Timer.h:356
void start()
Starting a single time measurement.
Definition: Timer.h:203
double total() const
Returns the total elapsed time of all performed time measurements.
Definition: Timer.h:304
double max_
The maximal time of all measurements.
Definition: Timer.h:150
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
Header file for basic type definitions.