10 #ifndef NANOVDB_CPU_TIMER_H_HAS_BEEN_INCLUDED 11 #define NANOVDB_CPU_TIMER_H_HAS_BEEN_INCLUDED 20 std::chrono::high_resolution_clock::time_point mStart;
28 CpuTimer(
const std::string &msg, std::ostream& os = std::cerr) {this->
start(msg, os);}
33 void start(
const std::string &msg, std::ostream& os = std::cerr)
35 os << msg <<
" ... " << std::flush;
36 mStart = std::chrono::high_resolution_clock::now();
40 template <
typename AccuracyT = std::chrono::milliseconds>
43 auto end = std::chrono::high_resolution_clock::now();
44 return std::chrono::duration_cast<AccuracyT>(end - mStart).count();
50 template <
typename AccuracyT = std::chrono::milliseconds>
51 void stop(std::ostream& os = std::cerr)
53 auto end = std::chrono::high_resolution_clock::now();
54 auto diff = std::chrono::duration_cast<AccuracyT>(end - mStart).count();
55 os <<
"completed in " << diff;
56 if (std::is_same<AccuracyT, std::chrono::microseconds>::value) {
57 os <<
" microseconds" << std::endl;
58 }
else if (std::is_same<AccuracyT, std::chrono::milliseconds>::value) {
59 os <<
" milliseconds" << std::endl;
60 }
else if (std::is_same<AccuracyT, std::chrono::seconds>::value) {
61 os <<
" seconds" << std::endl;
63 os <<
" unknown time unit" << std::endl;
71 template <
typename AccuracyT = std::chrono::milliseconds>
72 void restart(
const std::string &msg, std::ostream& os = std::cerr)
74 this->stop<AccuracyT>();
83 #endif // NANOVDB_CPU_TIMER_HAS_BEEN_INCLUDED auto elapsed()
elapsed time (since start) in miliseconds
Definition: CpuTimer.h:41
void stop(std::ostream &os=std::cerr)
stop the timer
Definition: CpuTimer.h:51
void start(const std::string &msg, std::ostream &os=std::cerr)
Start the timer.
Definition: CpuTimer.h:33
Definition: NanoVDB.h:247
CpuTimer()
Default constructor.
Definition: CpuTimer.h:23
CpuTimer(const std::string &msg, std::ostream &os=std::cerr)
Constructor that starts the timer.
Definition: CpuTimer.h:28
Definition: CpuTimer.h:18
void restart(const std::string &msg, std::ostream &os=std::cerr)
stop and start the timer
Definition: CpuTimer.h:72