Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JClock Class Reference

Auxiliary class for CPU timing. More...

#include <JClock.hh>

Inheritance diagram for JLANG::JClock:
JLANG::JTitle

Classes

struct  sentry
 Auxiliary data structure for scoped timing. More...
 

Public Member Functions

 JClock ()
 Default constructor.
 
 JClock (const JTitle &title)
 Constructor.
 
 ~JClock ()
 Destructor.
 
void reset ()
 Reset clock.
 
void start ()
 Start clock.
 
void stop ()
 Stop clock.
 
size_t operator() () const
 Get elapsed time.
 
void print (std::ostream &out) const
 Print clock data.
 
const std::string & getTitle () const
 Get title.
 
void setTitle (const std::string &title)
 Set title.
 

Static Public Member Functions

static void sets (std::ostream &out)
 Set output stream.
 

Static Protected Member Functions

static std::ostream *& gets ()
 Get output stream.
 

Protected Attributes

std::chrono::high_resolution_clock::time_point t0
 
std::chrono::high_resolution_clock::time_point t1
 
std::chrono::high_resolution_clock::duration ts
 
size_t count
 
std::string title
 

Friends

std::ostream & operator<< (std::ostream &out, const JClock &clock)
 Print clock data.
 

Detailed Description

Auxiliary class for CPU timing.

Definition at line 23 of file JClock.hh.

Constructor & Destructor Documentation

◆ JClock() [1/2]

JLANG::JClock::JClock ( )
inline

Default constructor.

Definition at line 30 of file JClock.hh.

30 :
31 JTitle(),
32 ts(0),
33 count(0)
34 {}
size_t count
Definition JClock.hh:179
std::chrono::high_resolution_clock::duration ts
Definition JClock.hh:178
JTitle()
Default constructor.
Definition JTitle.hh:24

◆ JClock() [2/2]

JLANG::JClock::JClock ( const JTitle & title)
inline

Constructor.

Parameters
titletitle

Definition at line 42 of file JClock.hh.

42 :
44 ts(0),
45 count(0)
46 {}
std::string title
Definition JTitle.hh:73

◆ ~JClock()

JLANG::JClock::~JClock ( )
inline

Destructor.

The clock data will optionally be printed to the set output stream.

Definition at line 54 of file JClock.hh.

55 {
56 if (gets() != NULL && count != 0) {
57 *gets() << (*this) << std::endl;
58 }
59 }
static std::ostream *& gets()
Get output stream.
Definition JClock.hh:186

Member Function Documentation

◆ reset()

void JLANG::JClock::reset ( )
inline

Reset clock.

Definition at line 93 of file JClock.hh.

94 {
95 ts = std::chrono::high_resolution_clock::duration(0);
96 count = 0;
97 }

◆ start()

void JLANG::JClock::start ( )
inline

Start clock.

Definition at line 103 of file JClock.hh.

104 {
105 t0 = std::chrono::high_resolution_clock::now();
106 }
std::chrono::high_resolution_clock::time_point t0
Definition JClock.hh:176

◆ stop()

void JLANG::JClock::stop ( )
inline

Stop clock.

Definition at line 112 of file JClock.hh.

113 {
114 t1 = std::chrono::high_resolution_clock::now();
115
116 ts += (t1 - t0);
117
118 ++count;
119 }
std::chrono::high_resolution_clock::time_point t1
Definition JClock.hh:177

◆ operator()()

size_t JLANG::JClock::operator() ( ) const
inline

Get elapsed time.

Returns
elapsed time [ns]

Definition at line 127 of file JClock.hh.

128 {
129 return ts / std::chrono::nanoseconds(1);
130 }

◆ print()

void JLANG::JClock::print ( std::ostream & out) const
inline

Print clock data.

Parameters
outoutput stream

Definition at line 138 of file JClock.hh.

139 {
140 using namespace std;
141
142 out << setw(16) << left << getTitle() << ' '
143 << setw(12) << right << count << ' '
144 << setw(12) << ts / std::chrono::milliseconds(1) << " [ms]";
145 }
const std::string & getTitle() const
Get title.
Definition JTitle.hh:55

◆ sets()

static void JLANG::JClock::sets ( std::ostream & out)
inlinestatic

Set output stream.

Parameters
outoutput stream

Definition at line 168 of file JClock.hh.

169 {
170 gets() = &out;
171 }

◆ gets()

static std::ostream *& JLANG::JClock::gets ( )
inlinestaticprotected

Get output stream.

Returns
output stream

Definition at line 186 of file JClock.hh.

187 {
188 static std::ostream* out = NULL;
189
190 return out;
191 }

◆ getTitle()

const std::string & JLANG::JTitle::getTitle ( ) const
inlineinherited

Get title.

Returns
title

Definition at line 55 of file JTitle.hh.

56 {
57 return this->title;
58 }

◆ setTitle()

void JLANG::JTitle::setTitle ( const std::string & title)
inlineinherited

Set title.

Parameters
titletitle

Definition at line 66 of file JTitle.hh.

67 {
68 this->title = title;
69 }

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JClock & clock )
friend

Print clock data.

Parameters
outoutput stream
clockclock
Returns
output stream

Definition at line 155 of file JClock.hh.

156 {
157 clock.print(out);
158
159 return out;
160 }

Member Data Documentation

◆ t0

std::chrono::high_resolution_clock::time_point JLANG::JClock::t0
protected

Definition at line 176 of file JClock.hh.

◆ t1

std::chrono::high_resolution_clock::time_point JLANG::JClock::t1
protected

Definition at line 177 of file JClock.hh.

◆ ts

std::chrono::high_resolution_clock::duration JLANG::JClock::ts
protected

Definition at line 178 of file JClock.hh.

◆ count

size_t JLANG::JClock::count
protected

Definition at line 179 of file JClock.hh.

◆ title

std::string JLANG::JTitle::title
protectedinherited

Definition at line 73 of file JTitle.hh.


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