10 #ifndef NANOVDB_UTIL_TIMER_H_HAS_BEEN_INCLUDED 11 #define NANOVDB_UTIL_TIMER_H_HAS_BEEN_INCLUDED 22 std::chrono::high_resolution_clock::time_point mStart;
30 Timer(
const std::string &msg, std::ostream& os = std::cerr) {this->
start(msg, os);}
35 void start(
const std::string &msg, std::ostream& os = std::cerr)
37 os << msg <<
" ... " << std::flush;
38 mStart = std::chrono::high_resolution_clock::now();
42 template <
typename AccuracyT = std::chrono::milliseconds>
45 auto end = std::chrono::high_resolution_clock::now();
46 return std::chrono::duration_cast<AccuracyT>(end - mStart).count();
52 template <
typename AccuracyT = std::chrono::milliseconds>
53 void stop(std::ostream& os = std::cerr)
55 auto end = std::chrono::high_resolution_clock::now();
56 auto diff = std::chrono::duration_cast<AccuracyT>(end - mStart).count();
57 os <<
"completed in " << diff;
58 if (std::is_same<AccuracyT, std::chrono::microseconds>::value) {
59 os <<
" microseconds" << std::endl;
60 }
else if (std::is_same<AccuracyT, std::chrono::milliseconds>::value) {
61 os <<
" milliseconds" << std::endl;
62 }
else if (std::is_same<AccuracyT, std::chrono::seconds>::value) {
63 os <<
" seconds" << std::endl;
65 os <<
" unknown time unit" << std::endl;
73 template <
typename AccuracyT = std::chrono::milliseconds>
74 void restart(
const std::string &msg, std::ostream& os = std::cerr)
76 this->stop<AccuracyT>();
83 using CpuTimer [[deprecated(
"Use nanovdb::util::Timer instead")]] =
util::Timer;
87 #endif // NANOVDB_UTIL_TIMER_HAS_BEEN_INCLUDED Timer(const std::string &msg, std::ostream &os=std::cerr)
Constructor that starts the timer.
Definition: Timer.h:30
void start(const std::string &msg, std::ostream &os=std::cerr)
Start the timer.
Definition: Timer.h:35
auto elapsed()
elapsed time (since start) in miliseconds
Definition: Timer.h:43
Definition: GridHandle.h:27
void stop(std::ostream &os=std::cerr)
stop the timer
Definition: Timer.h:53
Timer()
Default constructor.
Definition: Timer.h:25
void restart(const std::string &msg, std::ostream &os=std::cerr)
stop and start the timer
Definition: Timer.h:74