Blaze
3.9
Toggle main menu visibility
Loading...
Searching...
No Matches
blaze
util
timing
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
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
//*************************************************************************************************
171
template
<
typename
TP >
// Timing policy
172
inline
Timer<TP>::Timer
()
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
//*************************************************************************************************
202
template
<
typename
TP >
// Timing policy
203
inline
void
Timer<TP>::start
()
204
{
205
// Starting the time measurement and calculating a time stamp
206
start_
= TimingPolicy::getTimestamp();
207
}
208
//*************************************************************************************************
209
210
211
//*************************************************************************************************
219
template
<
typename
TP >
// Timing policy
220
inline
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
//*************************************************************************************************
255
template
<
typename
TP >
// Timing policy
256
inline
void
Timer<TP>::reset
()
257
{
258
counter_
= 0;
259
start_
= 0.0;
260
end_
= 0.0;
261
time_
= 0.0;
262
min_
= std::numeric_limits<double>::max();
263
max_
= 0.0;
264
last_
= 0.0;
265
}
266
//*************************************************************************************************
267
268
269
270
271
//=================================================================================================
272
//
273
// GET FUNCTIONS
274
//
275
//=================================================================================================
276
277
//*************************************************************************************************
282
template
<
typename
TP >
// Timing policy
283
inline
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
//*************************************************************************************************
303
template
<
typename
TP >
// Timing policy
304
inline
double
Timer<TP>::total
()
const
305
{
306
return
time_
;
307
}
308
//*************************************************************************************************
309
310
311
//*************************************************************************************************
316
template
<
typename
TP >
// Timing policy
317
inline
double
Timer<TP>::average
()
const
318
{
319
return
time_
/
counter_
;
320
}
321
//*************************************************************************************************
322
323
324
//*************************************************************************************************
329
template
<
typename
TP >
// Timing policy
330
inline
double
Timer<TP>::min
()
const
331
{
332
return
min_
;
333
}
334
//*************************************************************************************************
335
336
337
//*************************************************************************************************
342
template
<
typename
TP >
// Timing policy
343
inline
double
Timer<TP>::max
()
const
344
{
345
return
max_
;
346
}
347
//*************************************************************************************************
348
349
350
//*************************************************************************************************
355
template
<
typename
TP >
// Timing policy
356
inline
double
Timer<TP>::last
()
const
357
{
358
return
last_
;
359
}
360
//*************************************************************************************************
361
362
}
// timing
363
364
}
// blaze
365
366
#endif
Time.h
Header file for time functions.
blaze::timing::Timer< CpuPolicy >::end_
double end_
Definition
Timer.h:147
blaze::timing::Timer::max
double max() const
Returns the maximal time of all performed time measurements.
Definition
Timer.h:343
blaze::timing::Timer< CpuPolicy >::TimingPolicy
CpuPolicy TimingPolicy
Definition
Timer.h:107
blaze::timing::Timer::average
double average() const
Returns the average time of all performed time measurements.
Definition
Timer.h:317
blaze::timing::Timer::end
void end()
Ending a single time measurement.
Definition
Timer.h:220
blaze::timing::Timer::min
double min() const
Returns the minimal time of all performed time measurements.
Definition
Timer.h:330
blaze::timing::Timer::getCounter
size_t getCounter() const
Returns the total number of time measurements performed by this timer.
Definition
Timer.h:283
blaze::timing::Timer< CpuPolicy >::start_
double start_
Definition
Timer.h:146
blaze::timing::Timer::Timer
Timer()
Constructor of the Timer class.
Definition
Timer.h:172
blaze::timing::Timer< CpuPolicy >::last_
double last_
Definition
Timer.h:151
blaze::timing::Timer< CpuPolicy >::time_
double time_
Definition
Timer.h:148
blaze::timing::Timer< CpuPolicy >::min_
double min_
Definition
Timer.h:149
blaze::timing::Timer::reset
void reset()
Resetting the timer.
Definition
Timer.h:256
blaze::timing::Timer< CpuPolicy >::counter_
size_t counter_
Definition
Timer.h:145
blaze::timing::Timer::last
double last() const
Returns the last measured time.
Definition
Timer.h:356
blaze::timing::Timer::start
void start()
Starting a single time measurement.
Definition
Timer.h:203
blaze::timing::Timer::total
double total() const
Returns the total elapsed time of all performed time measurements.
Definition
Timer.h:304
blaze::timing::Timer< CpuPolicy >::max_
double max_
Definition
Timer.h:150
blaze::timing
Namespace for the time measurement module.
Definition
CpuPolicy.h:48
Types.h
Header file for basic type definitions.
Generated by
1.18.0