Jpp 21.0.0
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.
 
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.
 

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 24 of file JClock.hh.

Constructor & Destructor Documentation

◆ JClock() [1/2]

JLANG::JClock::JClock ( )
inline

Default constructor.

Definition at line 31 of file JClock.hh.

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

◆ JClock() [2/2]

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

Constructor.

Parameters
titletitle

Definition at line 43 of file JClock.hh.

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

Member Function Documentation

◆ reset()

void JLANG::JClock::reset ( )
inline

Reset clock.

Definition at line 81 of file JClock.hh.

82 {
83 ts = std::chrono::high_resolution_clock::duration(0);
84 count = 0;
85 }

◆ start()

void JLANG::JClock::start ( )
inline

Start clock.

Definition at line 91 of file JClock.hh.

92 {
93 t0 = std::chrono::high_resolution_clock::now();
94 }
std::chrono::high_resolution_clock::time_point t0
Definition JClock.hh:152

◆ stop()

void JLANG::JClock::stop ( )
inline

Stop clock.

Definition at line 100 of file JClock.hh.

101 {
102 t1 = std::chrono::high_resolution_clock::now();
103
104 ts += (t1 - t0);
105
106 ++count;
107 }
std::chrono::high_resolution_clock::time_point t1
Definition JClock.hh:153

◆ operator()()

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

Get elapsed time.

Returns
elapsed time [ns]

Definition at line 115 of file JClock.hh.

116 {
117 return ts / std::chrono::nanoseconds(1);
118 }

◆ print()

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

Print clock data.

Parameters
outoutput stream

Definition at line 126 of file JClock.hh.

127 {
128 using namespace std;
129
130 out << setw(16) << left << getTitle() << ' '
131 << setw(12) << right << count << ' '
132 << setw(12) << ts / std::chrono::milliseconds(1) << " [ms]";
133 }
const std::string & getTitle() const
Get title.
Definition JTitle.hh:55

◆ 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 143 of file JClock.hh.

144 {
145 clock.print(out);
146
147 return out;
148 }

Member Data Documentation

◆ t0

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

Definition at line 152 of file JClock.hh.

◆ t1

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

Definition at line 153 of file JClock.hh.

◆ ts

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

Definition at line 154 of file JClock.hh.

◆ count

size_t JLANG::JClock::count
protected

Definition at line 155 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: