walberla::timing::Timer< TP > Class Template Reference

Detailed Description

template<typename TP>
class walberla::timing::Timer< TP >

Progress timer for time and performance measurements.

The Timer class offers timing & benchmarking functionality for all kinds of applications. The following example code demonstrates the use of the WcTimer class, which combines the Timer class template with the WcPolicy for wall clock time measurements, for a single time measurement:

// Creating a new wall clock timer immediately starts a new time measurement
WcTimer timer;
... // program or code fragment to be measured
// Stopping the time measurement
timer.end();
// Evaluation of the measured time
double time = timer.last();

The timer class additionally offers the functionality to start several time measurements in order to evaluate minimal, maximal or average times. The next example demonstrates a possible setup for such a series of time measurements:

// Creating a new wall clock timer
WcTimer timer;
... // Additional setup code
// Starting 10 wall clock time measurements
for( unsigned int i=0; i<10; ++i ) {
timer.start();
... // program or code fragment to be measured
timer.end();
}
// After the measurements, the desired timing results can be calculated, as for instance the
// average wall clock time
double average = timer.average();

#include <Timer.h>

Public Types

using TimingPolicy = TP
 Timing policy of the Timer. More...
 

Public Member Functions

Constructor
 Timer ()
 Constructor of the Timer class. More...
 
 Timer (uint_t counter, double min, double max, double total, double sumOfSquares)
 Constructor of the Timer class. More...
 
Timing functions
void start ()
 Starting a single time measurement. More...
 
void end ()
 Ending a single time measurement. More...
 
void reset ()
 Resetting the timer. More...
 
Get functions
uint_t getCounter () const
 Returns the total number of time measurements performed by this timer. More...
 
Time evaluation functions
double total () const
 Returns the total elapsed time of all performed time measurements. More...
 
double sumOfSquares () const
 Returns the sum of each (time measurement)^2. More...
 
double average () const
 Returns the average time of all performed time measurements. More...
 
double variance () const
 Returns the variance of all performed time measurements. More...
 
double min () const
 Returns the minimal time of all performed time measurements. More...
 
double max () const
 Returns the maximal time of all performed time measurements. More...
 
double last () const
 Returns the last measured time. More...
 

Friends

template<typename T , typename G , typename TP2 >
mpi::GenericSendBuffer< T, G > & operator<< (mpi::GenericSendBuffer< T, G > &buf, const Timer< TP2 > &t)
 
template<typename T , typename TP2 >
mpi::GenericRecvBuffer< T > & operator>> (mpi::GenericRecvBuffer< T > &buf, Timer< TP2 > &t)
 

Related Functions

(Note that these are not member functions.)

template<typename TP >
void to_json (nlohmann::json &j, const Timer< TP > &timer)
 Converts timer to json The signature is required by the json library. More...
 

Utility functions for Timers

uint_t counter_
 Number of performed time measurements. More...
 
double start_
 Start of the current time measurement. More...
 
double end_
 End of the current time measurement. More...
 
double time_
 The total elapsed time of all measurements. More...
 
double sumOfSquares_
 Sum of each (time measurement)^2. More...
 
double min_
 The minimal time of all measurements. More...
 
double max_
 The maximal time of all measurements. More...
 
double last_
 The last measured time. More...
 
void merge (const Timer &other)
 Adds results of an other Timer to own results. More...
 

Member Typedef Documentation

◆ TimingPolicy

template<typename TP >
using walberla::timing::Timer< TP >::TimingPolicy = TP

Timing policy of the Timer.

Constructor & Destructor Documentation

◆ Timer() [1/2]

template<typename TP >
walberla::timing::Timer< TP >::Timer
inlineexplicit

Constructor of the Timer class.

The creation of a new timer immediately starts a new time measurement. It is possible to either restart the time measurement at a specific point of time or to continue the time measurement and to end it via the end() function.

◆ Timer() [2/2]

template<typename TP >
walberla::timing::Timer< TP >::Timer ( uint_t  _counter,
double  _min,
double  _max,
double  _total,
double  _sumOfSquares 
)
inlineexplicit

Constructor of the Timer class.

Initializes the timer with

Parameters
_counternumber of timing measurements already done
_minthe minimum time of the measurements
_maxthe maximum time of the measurements
_totalthe total time of all measurements
_sumOfSquareseach measurement time squared, then summed

Member Function Documentation

◆ average()

template<typename TP >
double walberla::timing::Timer< TP >::average
inline

Returns the average time of all performed time measurements.

Returns
The average time.

◆ end()

template<typename TP >
void walberla::timing::Timer< TP >::end
inline

Ending a single time measurement.

Returns
void

This function ends the currently running time measurement and performs the necessary statistical calculations.

◆ getCounter()

template<typename TP >
uint_t walberla::timing::Timer< TP >::getCounter
inline

Returns the total number of time measurements performed by this timer.

Returns
The number of performed time measurements.

◆ last()

template<typename TP >
double walberla::timing::Timer< TP >::last
inline

Returns the last measured time.

Returns
The last measured time.

◆ max()

template<typename TP >
double walberla::timing::Timer< TP >::max
inline

Returns the maximal time of all performed time measurements.

Returns
The maximal time.

◆ merge()

template<typename TP >
void walberla::timing::Timer< TP >::merge ( const Timer< TP > &  other)
inline

Adds results of an other Timer to own results.

◆ min()

template<typename TP >
double walberla::timing::Timer< TP >::min
inline

Returns the minimal time of all performed time measurements.

Returns
The minimal time.

◆ reset()

template<typename TP >
void walberla::timing::Timer< TP >::reset
inline

Resetting the timer.

Returns
void

This function completely resets the timer and all information on the performed time measurements. In order to start a new time measurement, the start() function has to be used.

◆ start()

template<typename TP >
void walberla::timing::Timer< TP >::start
inline

Starting a single time measurement.

Returns
void

This function starts a single time measurement.

◆ sumOfSquares()

template<typename TP >
double walberla::timing::Timer< TP >::sumOfSquares
inline

Returns the sum of each (time measurement)^2.

Can be used to calculate the variance using the formula Var(x) = 1/N * ( E(x^2) - E(x)^2)

Returns
sum of each (time measurement)^2

◆ total()

template<typename TP >
double walberla::timing::Timer< TP >::total
inline

Returns the total elapsed time of all performed time measurements.

Returns
The total elapsed time of all time measurements.

◆ variance()

template<typename TP >
double walberla::timing::Timer< TP >::variance
inline

Returns the variance of all performed time measurements.

Returns
The variance 1/N * ( E(x^2) - E(x)^2 ) where E is the expectation or average value

Friends And Related Function Documentation

◆ operator<<

template<typename TP >
template<typename T , typename G , typename TP2 >
mpi::GenericSendBuffer<T,G>& operator<< ( mpi::GenericSendBuffer< T, G > &  buf,
const Timer< TP2 > &  t 
)
friend

◆ operator>>

template<typename TP >
template<typename T , typename TP2 >
mpi::GenericRecvBuffer<T>& operator>> ( mpi::GenericRecvBuffer< T > &  buf,
Timer< TP2 > &  t 
)
friend

◆ to_json()

template<typename TP >
void to_json ( nlohmann::json &  j,
const Timer< TP > &  timer 
)
related

Converts timer to json The signature is required by the json library.

Member Data Documentation

◆ counter_

template<typename TP >
uint_t walberla::timing::Timer< TP >::counter_
private

Number of performed time measurements.

◆ end_

template<typename TP >
double walberla::timing::Timer< TP >::end_
private

End of the current time measurement.

◆ last_

template<typename TP >
double walberla::timing::Timer< TP >::last_
private

The last measured time.

◆ max_

template<typename TP >
double walberla::timing::Timer< TP >::max_
private

The maximal time of all measurements.

◆ min_

template<typename TP >
double walberla::timing::Timer< TP >::min_
private

The minimal time of all measurements.

◆ start_

template<typename TP >
double walberla::timing::Timer< TP >::start_
private

Start of the current time measurement.

◆ sumOfSquares_

template<typename TP >
double walberla::timing::Timer< TP >::sumOfSquares_
private

Sum of each (time measurement)^2.

◆ time_

template<typename TP >
double walberla::timing::Timer< TP >::time_
private

The total elapsed time of all measurements.


The documentation for this class was generated from the following files:
timing::Timer< timing::WcPolicy > WcTimer
Definition: Timer.h:597
double average() const
Returns the average time of all performed time measurements.
Definition: Timer.h:383
void start()
Starting a single time measurement.
Definition: Timer.h:248
void end()
Ending a single time measurement.
Definition: Timer.h:265