Go to the documentation of this file.
4 #ifndef OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED
5 #define OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED
70 CpuTimer(std::ostream& os = std::cerr) : mOutStream(os), mT0(this->now()) {}
75 CpuTimer(
const std::string& msg, std::ostream& os = std::cerr) : mOutStream(os) { this->start(msg); }
80 inline void start() { mT0 = this->now(); }
85 inline void start(
const std::string& msg)
87 mOutStream << msg <<
" ...";
96 return (this->now() - mT0);
104 static constexpr
double resolution = 1.0 / 1E3;
105 return static_cast<double>(this->microseconds()) * resolution;
113 static constexpr
double resolution = 1.0 / 1E6;
114 return static_cast<double>(this->microseconds()) * resolution;
120 inline std::string
time()
const
122 const double msec = this->milliseconds();
123 std::ostringstream os;
133 const double msec = this->milliseconds();
134 printTime(mOutStream, msec,
" completed in ",
"\n", 4, 3, 1);
141 inline double stop(
const std::string& msg)
const
143 const double msec = this->milliseconds();
144 mOutStream << msg <<
" ...";
145 printTime(mOutStream, msec,
" completed in ",
"\n", 4, 3, 1);
155 const double msec = this->milliseconds();
166 const double delta = this->stop();
177 const auto time_since_epoch =
178 std::chrono::steady_clock::now().time_since_epoch();
180 const auto microseconds =
181 std::chrono::duration_cast<std::chrono::microseconds>(time_since_epoch).count();
183 return static_cast<int64_t
>(microseconds);
186 std::ostream& mOutStream;
195 #endif // OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED
CpuTimer(std::ostream &os=std::cerr)
Initiate timer.
Definition: CpuTimer.h:70
double restart()
Re-start timer.
Definition: CpuTimer.h:153
void start()
Start timer.
Definition: CpuTimer.h:80
double milliseconds() const
Return Time difference in milliseconds since construction or start was called.
Definition: CpuTimer.h:102
double stop() const
Returns and prints time in milliseconds since construction or start was called.
Definition: CpuTimer.h:131
void start(const std::string &msg)
Print message and start timer.
Definition: CpuTimer.h:85
Library and file format version numbers.
double restart(const std::string &msg)
Stop previous timer, print message and re-start timer.
Definition: CpuTimer.h:164
CpuTimer(const std::string &msg, std::ostream &os=std::cerr)
Prints message and start timer.
Definition: CpuTimer.h:75
std::string time() const
Definition: CpuTimer.h:120
OPENVDB_DEPRECATED double delta() const
This method is identical to milliseconds() - deprecated.
Definition: CpuTimer.h:118
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:147
double seconds() const
Return Time difference in seconds since construction or start was called.
Definition: CpuTimer.h:111
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:95
Simple timer for basic profiling.
Definition: CpuTimer.h:67
double stop(const std::string &msg) const
Returns and prints time in milliseconds since construction or start was called.
Definition: CpuTimer.h:141
Definition: openvdb/Exceptions.h:13
OPENVDB_API int printTime(std::ostream &os, double milliseconds, const std::string &head="", const std::string &tail="\n", int width=4, int precision=1, int verbose=0)
int64_t microseconds() const
Return Time difference in microseconds since construction or start was called.
Definition: CpuTimer.h:94