Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::Timer Class Reference

#include <Timer.hh>

Public Member Functions

void Start ()
 
void Stop ()
 
bool IsValid () const
 
double GetRealElapsed () const
 
double GetSystemElapsed () const
 
double GetUserElapsed () const
 

Static Public Member Functions

static const char * GetClockTime ()
 

Detailed Description

Definition at line 106 of file Timer.hh.

Member Function Documentation

◆ GetClockTime()

const char * PTL::Timer::GetClockTime ( )
inlinestatic

Definition at line 155 of file Timer.hh.

156{
157 time_t rawtime;
158 struct tm* timeinfo;
159
160 time(&rawtime);
161 timeinfo = localtime(&rawtime);
162 return asctime(timeinfo);
163}

◆ GetRealElapsed()

double Timer::GetRealElapsed ( ) const

Definition at line 85 of file Timer.cc.

86{
87 if(!fValidTimes)
88 {
89 throw std::runtime_error("Timer::GetRealElapsed() - "
90 "Timer not stopped or times not recorded!");
91 }
92 std::chrono::duration<double> diff = fEndRealTime - fStartRealTime;
93 return diff.count();
94}

Referenced by PTL::operator<<().

◆ GetSystemElapsed()

double Timer::GetSystemElapsed ( ) const

Definition at line 99 of file Timer.cc.

100{
101 if(!fValidTimes)
102 {
103 throw std::runtime_error("Timer::GetSystemElapsed() - "
104 "Timer not stopped or times not recorded!");
105 }
106 double diff = fEndTimes.tms_stime - fStartTimes.tms_stime;
107 return diff / sysconf(_SC_CLK_TCK);
108}

Referenced by PTL::operator<<().

◆ GetUserElapsed()

double Timer::GetUserElapsed ( ) const

Definition at line 113 of file Timer.cc.

114{
115 if(!fValidTimes)
116 {
117 throw std::runtime_error("Timer::GetUserElapsed() - "
118 "Timer not stopped or times not recorded!");
119 }
120 double diff = fEndTimes.tms_utime - fStartTimes.tms_utime;
121 return diff / sysconf(_SC_CLK_TCK);
122}

Referenced by PTL::operator<<().

◆ IsValid()

bool PTL::Timer::IsValid ( ) const
inline

Definition at line 149 of file Timer.hh.

150{
151 return fValidTimes;
152}

Referenced by PTL::operator<<().

◆ Start()

void PTL::Timer::Start ( )
inline

Definition at line 133 of file Timer.hh.

134{
135 fValidTimes = false;
136 times(&fStartTimes);
137 fStartRealTime = clock_type::now();
138}

◆ Stop()

void PTL::Timer::Stop ( )
inline

Definition at line 141 of file Timer.hh.

142{
143 times(&fEndTimes);
144 fEndRealTime = clock_type::now();
145 fValidTimes = true;
146}

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