profiler  0.0
molpro::profiler::Timer Class Reference

Measures cpu or wall time. Can be constructed as a dummy that is always stopped. More...

#include <Timer.h>

Public Types

enum  Type {
  cpu ,
  wall
}
 

Public Member Functions

 Timer (Type type, bool is_dummy)
 
 Timer (double cumulative_time, Type type, bool is_dummy)
 Construct Timer with initial cumulative time. More...
 
Timerstart ()
 start timing More...
 
Timerstop ()
 Stops timing, storing time since creation in cumulative. More...
 
void operator+= (const Timer &other)
 updates cumulative time More...
 
double start_time () const
 
double stop_time () const
 
double cumulative_time () const
 Cumulative time over all start/stop periods. If active than it includes the time from start to current moment. More...
 
bool stopped () const
 Timer is stopped and is not timing. More...
 
bool dummy () const
 Timer is dummy and does nothing. More...
 
void reset ()
 Reset the timer erasing all data. More...
 
Type type () const
 type of timer More...
 

Detailed Description

Measures cpu or wall time. Can be constructed as a dummy that is always stopped.

The timer is started with start() and stopped with stop(). Repetitive calls to start() do not cause a restart, and the start time from the first call is kept.

Basic usage,

auto t = Timer(Type::wall, false);
t.start()
// do some work
t.stop()
// ...
std::cout << "the work took = " << t.cumulative_time() << " seconds " << std::endl;
Timer(Type type, bool is_dummy)
Definition: Timer.cpp:15

The timer measures cumulative time from all start/stop calls.

Calling cumulative_time() while the timer is running returns the cumulative time at this moment without stopping. For example,

auto t = Timer(Type::wall, false);
t.start();
// 1 second of work
std::cout << "should say 1: " << t.cumulative_time() << std::endl;
// another second of work
std::cout << "should say 2: " << t.cumulative_time() << std::endl;
t.stop()
// lots more work
std::cout << "should still say 2: " << t.cumulative_time() << std::endl;

Member Enumeration Documentation

◆ Type

Enumerator
cpu 
wall 

Constructor & Destructor Documentation

◆ Timer() [1/2]

molpro::profiler::Timer::Timer ( Timer::Type  _type,
bool  is_dummy 
)

◆ Timer() [2/2]

molpro::profiler::Timer::Timer ( double  cumulative_time,
Timer::Type  type,
bool  is_dummy 
)

Construct Timer with initial cumulative time.

Member Function Documentation

◆ cumulative_time()

double molpro::profiler::Timer::cumulative_time ( ) const

Cumulative time over all start/stop periods. If active than it includes the time from start to current moment.

◆ dummy()

bool molpro::profiler::Timer::dummy ( ) const
inline

Timer is dummy and does nothing.

◆ operator+=()

void molpro::profiler::Timer::operator+= ( const Timer other)

updates cumulative time

◆ reset()

void molpro::profiler::Timer::reset ( )

Reset the timer erasing all data.

◆ start()

Timer & molpro::profiler::Timer::start ( )

start timing

◆ start_time()

double molpro::profiler::Timer::start_time ( ) const
inline

◆ stop()

Timer & molpro::profiler::Timer::stop ( )

Stops timing, storing time since creation in cumulative.

◆ stop_time()

double molpro::profiler::Timer::stop_time ( ) const
inline

◆ stopped()

bool molpro::profiler::Timer::stopped ( ) const
inline

Timer is stopped and is not timing.

◆ type()

Type molpro::profiler::Timer::type ( ) const
inline

type of timer