DOLFINx 0.10.0.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
Timer< T > Class Template Reference

Timer for measuring and logging elapsed time durations. More...

#include <Timer.h>

Public Member Functions

 Timer (std::optional< std::string > task=std::nullopt)
 Create and start timer.
 
 ~Timer ()
 
void start ()
 Reset elapsed time and (re-)start timer.
 
template<typename Period = std::ratio<1>>
std::chrono::duration< double, Period > elapsed () const
 Elapsed time since time has been started.
 
template<typename Period = std::ratio<1>>
std::chrono::duration< double, Period > stop ()
 Stop timer and return elapsed time.
 
void resume ()
 Resume a stopped timer.
 
void flush ()
 Flush timer duration to the logger.
 

Detailed Description

template<typename T = std::chrono::high_resolution_clock>
class dolfinx::common::Timer< T >

Timer for measuring and logging elapsed time durations.

The basic usage is

Timer timer("Assembling over cells");
Timer for measuring and logging elapsed time durations.
Definition Timer.h:41

The timer is started at construction and timing ends when the timer is destroyed (goes out-of-scope). The timer can be started (reset) and stopped explicitly by

timer.start();
/* .... */
timer.stop();

A summary of registered elapsed times can be printed by calling:

void list_timings(MPI_Comm comm, Table::Reduction reduction=Table::Reduction::max)
List a summary of timings and tasks.
Definition timing.cpp:18

Registered elapsed times are logged when (1) the timer goes out-of-scope or (2) Timer::flush() is called.

Constructor & Destructor Documentation

◆ Timer()

template<typename T = std::chrono::high_resolution_clock>
Timer ( std::optional< std::string > task = std::nullopt)
inline

Create and start timer.

Elapsed time is optionally registered in the logger when the Timer destructor is called.

Parameters
[in]taskName used to registered the elapsed time in the logger. If no name is set, the elapsed time is not registered in the logger.

◆ ~Timer()

template<typename T = std::chrono::high_resolution_clock>
~Timer ( )
inline

If timer is still running, it is stopped. Elapsed time is registered in the logger.

Member Function Documentation

◆ elapsed()

template<typename T = std::chrono::high_resolution_clock>
template<typename Period = std::ratio<1>>
std::chrono::duration< double, Period > elapsed ( ) const
inline

Elapsed time since time has been started.

Default duration unit is seconds.

Returns
Elapsed time duration.

◆ flush()

template<typename T = std::chrono::high_resolution_clock>
void flush ( )
inline

Flush timer duration to the logger.

An instance of a timer can be flushed to the logger only once. Subsequent calls will have no effect and will not trigger any logging.

Precondition
Timer must have been stopped before flushing.

◆ resume()

template<typename T = std::chrono::high_resolution_clock>
void resume ( )
inline

Resume a stopped timer.

Does nothing if timer has not been stopped.

◆ stop()

template<typename T = std::chrono::high_resolution_clock>
template<typename Period = std::ratio<1>>
std::chrono::duration< double, Period > stop ( )
inline

Stop timer and return elapsed time.

Default duration unit is seconds.

Returns
Elapsed time duration.

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