4 #ifndef OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED 5 #define OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED 7 #include <openvdb/version.h> 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;
117 inline std::string
time()
const 119 const double msec = this->milliseconds();
120 std::ostringstream os;
130 const double msec = this->milliseconds();
131 printTime(mOutStream, msec,
" completed in ",
"\n", 4, 3, 1);
138 inline double stop(
const std::string& msg)
const 140 const double msec = this->milliseconds();
141 mOutStream << msg <<
" ...";
142 printTime(mOutStream, msec,
" completed in ",
"\n", 4, 3, 1);
152 const double msec = this->milliseconds();
163 const double delta = this->stop();
174 const auto time_since_epoch =
175 std::chrono::steady_clock::now().time_since_epoch();
177 const auto microseconds =
178 std::chrono::duration_cast<std::chrono::microseconds>(time_since_epoch).count();
180 return static_cast<int64_t
>(microseconds);
183 std::ostream& mOutStream;
192 #endif // OPENVDB_UTIL_CPUTIMER_HAS_BEEN_INCLUDED void start(const std::string &msg)
Print message and start timer.
Definition: CpuTimer.h:85
Simple timer for basic profiling.
Definition: CpuTimer.h:66
double seconds() const
Return Time difference in seconds since construction or start was called.
Definition: CpuTimer.h:111
double stop(const std::string &msg) const
Returns and prints time in milliseconds since construction or start was called.
Definition: CpuTimer.h:138
void start()
Start timer.
Definition: CpuTimer.h:80
int64_t microseconds() const
Return Time difference in microseconds since construction or start was called.
Definition: CpuTimer.h:94
double stop() const
Returns and prints time in milliseconds since construction or start was called.
Definition: CpuTimer.h:128
std::string time() const
Definition: CpuTimer.h:117
Definition: Exceptions.h:13
CpuTimer(const std::string &msg, std::ostream &os=std::cerr)
Prints message and start timer.
Definition: CpuTimer.h:75
CpuTimer(std::ostream &os=std::cerr)
Initiate timer.
Definition: CpuTimer.h:70
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)
double milliseconds() const
Return Time difference in milliseconds since construction or start was called.
Definition: CpuTimer.h:102
double restart(const std::string &msg)
Stop previous timer, print message and re-start timer.
Definition: CpuTimer.h:161
double restart()
Re-start timer.
Definition: CpuTimer.h:150
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218