NEST  2.6.0,not_revisioned_source_dir@0
Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
nest::Stopwatch Class Reference

#include <stopwatch.h>

Public Types

enum  {
  MICROSEC = (timeunit_t)1, MILLISEC = MICROSEC * 1000, SECONDS = MILLISEC * 1000, MINUTES = SECONDS * 60,
  HOURS = MINUTES * 60, DAYS = HOURS * 24
}
 
typedef size_t timestamp_t
 
typedef size_t timeunit_t
 

Public Member Functions

 Stopwatch ()
 Creates a stopwatch that is not running. More...
 
void start ()
 Starts or resumes the stopwatch, if it is not running already. More...
 
void stop ()
 Stops the stopwatch, if it is not stopped already. More...
 
bool isRunning () const
 Returns, whether the stopwatch is running. More...
 
double elapsed (timeunit_t timeunit=SECONDS) const
 Returns the time elapsed between the start and stop of the stopwatch. More...
 
timestamp_t elapsed_timestamp () const
 Returns the time elapsed between the start and stop of the stopwatch. More...
 
void reset ()
 Resets the stopwatch. More...
 
void print (const char *msg="", timeunit_t timeunit=SECONDS, std::ostream &os=std::cout) const
 This method prints out the currently elapsed time. More...
 

Static Public Member Functions

static bool correct_timeunit (timeunit_t t)
 

Static Private Member Functions

static timestamp_t get_timestamp ()
 Returns current time in microseconds since EPOCH. More...
 

Private Attributes

timestamp_t _beg
 
timestamp_t _end
 
size_t _prev_elapsed
 
bool _running
 

Friends

std::ostream & operator<< (std::ostream &os, const Stopwatch &stopwatch)
 Convenient method for writing time in seconds to some ostream. More...
 

Member Typedef Documentation

Member Enumeration Documentation

anonymous enum
Enumerator
MICROSEC 
MILLISEC 
SECONDS 
MINUTES 
HOURS 
DAYS 

Constructor & Destructor Documentation

nest::Stopwatch::Stopwatch ( )
inline

Creates a stopwatch that is not running.

References reset().

Member Function Documentation

bool nest::Stopwatch::correct_timeunit ( timeunit_t  t)
inlinestatic

References DAYS, HOURS, MICROSEC, MILLISEC, MINUTES, and SECONDS.

Referenced by elapsed(), and print().

double nest::Stopwatch::elapsed ( timeunit_t  timeunit = SECONDS) const
inline

Returns the time elapsed between the start and stop of the stopwatch.

If it is running, it returns the time from start until now. If the stopwatch is run previously, the previous runtime is added. If you want only the last measurment, you have to reset the timer, before stating the measurment. Does not change the running state.

References assert(), correct_timeunit(), and elapsed_timestamp().

Referenced by print(), nest::Communicator::time_communicate(), nest::Communicator::time_communicate_alltoall(), nest::Communicator::time_communicate_alltoallv(), nest::Communicator::time_communicate_offgrid(), and nest::Communicator::time_communicatev().

nest::Stopwatch::timestamp_t nest::Stopwatch::elapsed_timestamp ( ) const
inline

Returns the time elapsed between the start and stop of the stopwatch.

If it is running, it returns the time from start until now. If the stopwatch is run previously, the previous runtime is added. If you want only the last measurment, you have to reset the timer, before stating the measurment. Does not change the running state. In contrast to Stopwatch::elapsed(), only the timestamp is returned, that is the number if microseconds as an integer.

References _beg, _end, _prev_elapsed, get_timestamp(), and isRunning().

Referenced by elapsed().

nest::Stopwatch::timestamp_t nest::Stopwatch::get_timestamp ( )
inlinestaticprivate

Returns current time in microseconds since EPOCH.

References SECONDS.

Referenced by elapsed_timestamp(), start(), and stop().

bool nest::Stopwatch::isRunning ( ) const
inline

Returns, whether the stopwatch is running.

References _running.

Referenced by elapsed_timestamp(), start(), and stop().

void nest::Stopwatch::print ( const char *  msg = "",
timeunit_t  timeunit = SECONDS,
std::ostream &  os = std::cout 
) const
inline

This method prints out the currently elapsed time.

References _beg, _end, _prev_elapsed, _running, assert(), correct_timeunit(), DAYS, numerics::e, elapsed(), HOURS, MICROSEC, MILLISEC, MINUTES, and SECONDS.

Referenced by nest::operator<<().

void nest::Stopwatch::reset ( )
inline

Resets the stopwatch.

References _beg, _end, _prev_elapsed, and _running.

Referenced by Stopwatch().

void nest::Stopwatch::start ( )
inline
void nest::Stopwatch::stop ( )
inline

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Stopwatch stopwatch 
)
friend

Convenient method for writing time in seconds to some ostream.

Member Data Documentation

timestamp_t nest::Stopwatch::_beg
private

Referenced by elapsed_timestamp(), print(), reset(), and start().

timestamp_t nest::Stopwatch::_end
private
size_t nest::Stopwatch::_prev_elapsed
private

Referenced by elapsed_timestamp(), print(), reset(), and start().

bool nest::Stopwatch::_running
private

Referenced by isRunning(), print(), reset(), start(), and stop().


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