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, mStop;
 
   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();
 
 
   44        mStop = std::chrono::high_resolution_clock::now();
 
 
   50        return std::chrono::duration_cast<std::chrono::milliseconds>(mStop - mStart).count();
 
 
   54    template <
typename AccuracyT = std::chrono::milliseconds>
 
   58        return std::chrono::duration_cast<AccuracyT>(mStop - mStart).count();
 
 
   64    template <
typename AccuracyT = std::chrono::milliseconds>
 
   65    void stop(std::ostream& os = std::cerr)
 
   67        mStop = std::chrono::high_resolution_clock::now();
 
   68        auto diff = std::chrono::duration_cast<AccuracyT>(mStop - mStart).count();
 
   69        os << 
"completed in " << diff;
 
   70        if (std::is_same<AccuracyT, std::chrono::microseconds>::value) {
 
   71            os << 
" microseconds" << std::endl;
 
   72        } 
else if (std::is_same<AccuracyT, std::chrono::milliseconds>::value) {
 
   73            os << 
" milliseconds" << std::endl;
 
   74        } 
else if (std::is_same<AccuracyT, std::chrono::seconds>::value) {
 
   75            os << 
" seconds" << std::endl;
 
   77            os << 
" unknown time unit" << std::endl;
 
 
   85    template <
typename AccuracyT = std::chrono::milliseconds>
 
   86    void restart(
const std::string &msg, std::ostream& os = std::cerr)
 
 
 
   95using CpuTimer [[deprecated(
"Use nanovdb::util::Timer instead")]] = util::Timer;
 
Timer()
Default constructor.
Definition Timer.h:25
Timer()
Default constructor.
Definition Timer.h:25
void restart(const std::string &msg, std::ostream &os=std::cerr)
stop and start the timer again
Definition Timer.h:86
void stop(std::ostream &os=std::cerr)
stop the timer and print elapsed time to a stream
Definition Timer.h:65
auto elapsed()
call record and return the elapsed time (since start) in miliseconds
Definition Timer.h:55
void start(const std::string &msg, std::ostream &os=std::cerr)
Start the timer.
Definition Timer.h:35
void record()
Record the stop time so the elapsed time since start can be computed.
Definition Timer.h:42
float milliseconds() const
Returns the time in milliseconds since record was called.
Definition Timer.h:48
Timer(const std::string &msg, std::ostream &os=std::cerr)
Constructor that starts the timer.
Definition Timer.h:30
Definition GridHandle.h:27