Time Class Reference

Allows for timing the algorithms; accurate up to 0.01 sec. More...

#include <MercuryTime.h>

Public Member Functions

 Time ()
 
void tic ()
 This is like a start button of a stopwatch. Assigns the variable start with the current number of clock ticks. More...
 
Mdouble toc ()
 This is like a stop button of a stopwatch. Assigns the variable finish to the current value of ticks returned by clock(). More...
 
Mdouble getCPUTime () const
 
Mdouble getWallTime ()
 
Mdouble toctic ()
 Outputs the toc value and resets the start time. More...
 

Private Attributes

clock_t start
 Stores the number of clock ticks, called by Time::tic(). More...
 
std::chrono::time_point< std::chrono::high_resolution_clock > wallClockStart
 
clock_t finish
 Stores the number of clock ticks, called by Time::toc(). More...
 
std::chrono::time_point< std::chrono::high_resolution_clock > wallClockFinish
 

Detailed Description

Allows for timing the algorithms; accurate up to 0.01 sec.

Calculates the amount of computational time used, in seconds. Works on the same concept of stopwatch, where one presses start and stops when needed. The difference returns the total time used up. Usage: Time time; ...; std::cout << time.toc();

Constructor & Destructor Documentation

◆ Time()

Time::Time ( )
inline
49  {
50  tic();
51  start = 0;
52  finish = 0;
53  }
clock_t finish
Stores the number of clock ticks, called by Time::toc().
Definition: MercuryTime.h:113
clock_t start
Stores the number of clock ticks, called by Time::tic().
Definition: MercuryTime.h:107
void tic()
This is like a start button of a stopwatch. Assigns the variable start with the current number of clo...
Definition: MercuryTime.h:59

References finish, start, and tic().

Member Function Documentation

◆ getCPUTime()

Mdouble Time::getCPUTime ( ) const
inline

Returns the time elapsed (in seconds) between tic and toc.

81  {
82  return (Mdouble(finish) - Mdouble(start)) / CLOCKS_PER_SEC;
83  }
double Mdouble
Definition: GeneralDefine.h:34

References finish, and start.

Referenced by DPMBase::getCPUTime().

◆ getWallTime()

Mdouble Time::getWallTime ( )
inline

Returns the time elapsed (in seconds) between tic and toc.

89  {
90  return std::chrono::duration<double>(wallClockFinish-wallClockStart).count();
91  }
std::chrono::time_point< std::chrono::high_resolution_clock > wallClockStart
Definition: MercuryTime.h:108
std::chrono::time_point< std::chrono::high_resolution_clock > wallClockFinish
Definition: MercuryTime.h:114

References wallClockFinish, and wallClockStart.

Referenced by DPMBase::getWallTime(), and toc().

◆ tic()

void Time::tic ( )
inline

This is like a start button of a stopwatch. Assigns the variable start with the current number of clock ticks.

60  {
61  start = clock(); //clock tics
62  wallClockStart = std::chrono::high_resolution_clock::now();
63  }

References start, and wallClockStart.

Referenced by main(), DPMBase::solve(), and Time().

◆ toc()

Mdouble Time::toc ( )
inline

This is like a stop button of a stopwatch. Assigns the variable finish to the current value of ticks returned by clock().

Returns
However, it also returns the total real time in seconds.
71  {
72  finish = clock();
73  wallClockFinish = std::chrono::high_resolution_clock::now();
74  return getWallTime();
75  }
Mdouble getWallTime()
Definition: MercuryTime.h:88

References finish, getWallTime(), and wallClockFinish.

Referenced by main(), DPMBase::solve(), and toctic().

◆ toctic()

Mdouble Time::toctic ( )
inline

Outputs the toc value and resets the start time.

97  {
98  Mdouble tocTime = toc();
99  start = finish;
100  return tocTime;
101  }
Mdouble toc()
This is like a stop button of a stopwatch. Assigns the variable finish to the current value of ticks ...
Definition: MercuryTime.h:70

References finish, start, and toc().

Referenced by main().

Member Data Documentation

◆ finish

clock_t Time::finish
private

Stores the number of clock ticks, called by Time::toc().

Referenced by getCPUTime(), Time(), toc(), and toctic().

◆ start

clock_t Time::start
private

Stores the number of clock ticks, called by Time::tic().

Referenced by getCPUTime(), tic(), Time(), and toctic().

◆ wallClockFinish

std::chrono::time_point<std::chrono::high_resolution_clock> Time::wallClockFinish
private

Referenced by getWallTime(), and toc().

◆ wallClockStart

std::chrono::time_point<std::chrono::high_resolution_clock> Time::wallClockStart
private

Referenced by getWallTime(), and tic().


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