HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openvdb::OPENVDB_VERSION_NAME::util::CpuTimer Class Reference

Simple timer for basic profiling. More...

#include <CpuTimer.h>

Public Member Functions

 CpuTimer (std::ostream &os=std::cerr)
 Initiate timer. More...
 
 CpuTimer (const std::string &msg, std::ostream &os=std::cerr)
 Prints message and start timer. More...
 
void start ()
 Start timer. More...
 
void start (const std::string &msg)
 Print message and start timer. More...
 
int64_t microseconds () const
 Return Time difference in microseconds since construction or start was called. More...
 
double milliseconds () const
 Return Time difference in milliseconds since construction or start was called. More...
 
double seconds () const
 Return Time difference in seconds since construction or start was called. More...
 
std::string time () const
 
double stop () const
 Returns and prints time in milliseconds since construction or start was called. More...
 
double stop (const std::string &msg) const
 Returns and prints time in milliseconds since construction or start was called. More...
 
double restart ()
 Re-start timer. More...
 
double restart (const std::string &msg)
 Stop previous timer, print message and re-start timer. More...
 

Detailed Description

Simple timer for basic profiling.

util::CpuTimer timer;
// code here will not be timed!
timer.start("algorithm");
// code to be timed goes here
timer.stop();

or to time multiple blocks of code

util::CpuTimer timer("algorithm 1");
// code to be timed goes here
timer.restart("algorithm 2");
// code to be timed goes here
timer.stop();

or to measure speedup between multiple runs

util::CpuTimer timer("algorithm 1");
// code for the first run goes here
const double t1 = timer.restart("algorithm 2");
// code for the second run goes here
const double t2 = timer.stop();
std::cerr << "Algorithm 1 is " << (t2/t1)
<< " timers faster than algorithm 2\n";

or to measure multiple blocks of code with deferred output

util::CpuTimer timer();
// code here will not be timed!
timer.start();
// code for the first run goes here
const double t1 = timer.restart();//time in milliseconds
// code for the second run goes here
const double t2 = timer.restart();//time in milliseconds
// code here will not be timed!
util::printTime(std::cout, t1, "Algorithm 1 completed in ");
util::printTime(std::cout, t2, "Algorithm 2 completed in ");

Definition at line 66 of file CpuTimer.h.

Constructor & Destructor Documentation

openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::CpuTimer ( std::ostream &  os = std::cerr)
inline

Initiate timer.

Definition at line 70 of file CpuTimer.h.

openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::CpuTimer ( const std::string msg,
std::ostream &  os = std::cerr 
)
inline

Prints message and start timer.

Note
Should normally be followed by a call to stop()

Definition at line 75 of file CpuTimer.h.

Member Function Documentation

int64_t openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::microseconds ( ) const
inline

Return Time difference in microseconds since construction or start was called.

Note
Combine this method with start() to get timing without any outputs.

Definition at line 94 of file CpuTimer.h.

double openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::milliseconds ( ) const
inline

Return Time difference in milliseconds since construction or start was called.

Note
Combine this method with start() to get timing without any outputs.

Definition at line 102 of file CpuTimer.h.

double openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::restart ( )
inline

Re-start timer.

Returns
time in milliseconds since previous start or restart.
Note
Should normally be followed by a call to stop() or restart()

Definition at line 150 of file CpuTimer.h.

double openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::restart ( const std::string msg)
inline

Stop previous timer, print message and re-start timer.

Returns
time in milliseconds since previous start or restart.
Note
Should normally be followed by a call to stop() or restart()

Definition at line 161 of file CpuTimer.h.

double openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::seconds ( ) const
inline

Return Time difference in seconds since construction or start was called.

Note
Combine this method with start() to get timing without any outputs.

Definition at line 111 of file CpuTimer.h.

void openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::start ( )
inline

Start timer.

Note
Should normally be followed by a call to milliseconds() or stop(std::string)

Definition at line 80 of file CpuTimer.h.

void openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::start ( const std::string msg)
inline

Print message and start timer.

Note
Should normally be followed by a call to stop()

Definition at line 85 of file CpuTimer.h.

double openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::stop ( ) const
inline

Returns and prints time in milliseconds since construction or start was called.

Note
Combine this method with start(std::string) to print at start and stop of task being timed.

Definition at line 128 of file CpuTimer.h.

double openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::stop ( const std::string msg) const
inline

Returns and prints time in milliseconds since construction or start was called.

Note
Combine this method with start() to delay output of task being timed.

Definition at line 138 of file CpuTimer.h.

std::string openvdb::OPENVDB_VERSION_NAME::util::CpuTimer::time ( ) const
inline

Definition at line 117 of file CpuTimer.h.


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