A monte carlo pin cell spectral code for nuclear engineering applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Timer Class Reference

The Timer represents a simulation stopwatch. More...

#include "pinspec/src/Timer.h"

Public Member Functions

 Timer ()
 Timer class constructor. More...
 
virtual ~Timer ()
 Default Timer destructor.
 
void start ()
 Starts the Timer in a similar fashion to starting a stopwatch.
 
void stop ()
 Stops the timer in a similar fashion to stopping a stopwatch.
 
void restart ()
 Restarts the timer. More...
 
void reset ()
 Resets the timer in a similar fashion to resetting a stopwatch.
 
void recordSplit (const char *msg)
 Records a message corresponding to a given time recorded by the timer. More...
 
double getTime ()
 Returns the amount of time elapsed from start to stop of the timer. More...
 
double diff (timespec start, timespec end)
 Helper function which computes the time between the values of two timespec structs. More...
 
void printSplits ()
 Prints the Timer's splits to the console. More...
 

Protected Attributes

timespec _start_time
 
timespec _end_time
 
double _elapsed_time
 
bool _running
 
std::vector< std::pair< double,
const char * > > 
_timer_splits
 

Detailed Description

The Timer represents a simulation stopwatch.

The timer class is for profiling code. It outputs running time in seconds but has resolution of microseconds on OSX and nanoseconds on Linux machines.

Constructor & Destructor Documentation

Timer::Timer ( )

Timer class constructor.

Sets the default elapsed time to 0.0 and the stopwatch running attribute to false.

Member Function Documentation

double Timer::diff ( timespec  start,
timespec  end 
)

Helper function which computes the time between the values of two timespec structs.

Parameters
startthe start time timespec struct
endthe end time timespec struct
double Timer::getTime ( )

Returns the amount of time elapsed from start to stop of the timer.

If the timer is currently runnning, returns the time from the timer start to the present time.

Returns
the elapsed time
void Timer::printSplits ( )

Prints the Timer's splits to the console.

This method will loop through all of the Timer's splits and print a formatted message string (80 characters in length) to the console with the message and the time corresponding to that message

void Timer::recordSplit ( const char *  msg)

Records a message corresponding to a given time recorded by the timer.

When this method is called it assumes that the timer has been stopped and has the current time for the process corresponding to the message.

Parameters
msga msg corresponding to this timer split
void Timer::restart ( )

Restarts the timer.

The elapsed time will accumulate along with the previous time(s) the timer was running. If the timer was already running, this function does nothing.

Member Data Documentation

double Timer::_elapsed_time
protected

The elapsed time between start and stop for a split

timespec Timer::_end_time
protected

The end time of a timer split

bool Timer::_running
protected

Boolean representing whether or not the time is presently running

timespec Timer::_start_time
protected

The start time of a timer split

std::vector< std::pair<double, const char*> > Timer::_timer_splits
protected

A container of times corresponding to messages for each split


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