10#ifndef NANOVDB_UTIL_TIMER_H_HAS_BEEN_INCLUDED
11#define NANOVDB_UTIL_TIMER_H_HAS_BEEN_INCLUDED
24 std::chrono::high_resolution_clock::time_point mStart, mStop;
32 Timer(
const std::string &msg, std::ostream& os = std::cerr) {this->
start(msg, os);}
37 void start(
const std::string &msg, std::ostream& os = std::cerr)
39 os << msg <<
" ... " << std::flush;
40 mStart = std::chrono::high_resolution_clock::now();
46 mStop = std::chrono::high_resolution_clock::now();
52 return static_cast<float>(std::chrono::duration_cast<std::chrono::milliseconds>(mStop - mStart).count());
56 template <
typename AccuracyT = std::chrono::milliseconds>
60 return std::chrono::duration_cast<AccuracyT>(mStop - mStart).count();
66 template <
typename AccuracyT = std::chrono::milliseconds>
67 void stop(std::ostream& os = std::cerr)
69 mStop = std::chrono::high_resolution_clock::now();
70 auto diff = std::chrono::duration_cast<AccuracyT>(mStop - mStart).count();
71 os <<
"completed in " << diff;
72 if (std::is_same<AccuracyT, std::chrono::microseconds>::value) {
73 os <<
" microseconds" << std::endl;
74 }
else if (std::is_same<AccuracyT, std::chrono::milliseconds>::value) {
75 os <<
" milliseconds" << std::endl;
76 }
else if (std::is_same<AccuracyT, std::chrono::seconds>::value) {
77 os <<
" seconds" << std::endl;
79 os <<
" unknown time unit" << std::endl;
87 template <
typename AccuracyT = std::chrono::milliseconds>
88 void restart(
const std::string &msg, std::ostream& os = std::cerr)
Timer()
Default constructor.
Definition Timer.h:27
void restart(const std::string &msg, std::ostream &os=std::cerr)
stop and start the timer again
Definition Timer.h:88
void stop(std::ostream &os=std::cerr)
stop the timer and print elapsed time to a stream
Definition Timer.h:67
auto elapsed()
call record and return the elapsed time (since start) in miliseconds
Definition Timer.h:57
void start(const std::string &msg, std::ostream &os=std::cerr)
Start the timer.
Definition Timer.h:37
void record()
Record the stop time so the elapsed time since start can be computed.
Definition Timer.h:44
float milliseconds() const
Returns the time in milliseconds since record was called.
Definition Timer.h:50
Timer(const std::string &msg, std::ostream &os=std::cerr)
Constructor that starts the timer.
Definition Timer.h:32
Definition GridChecksum.h:86
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:34