#pragma once #include #include class Timer { public: std::string name_; Timer(std::string name):name_(name){}; Timer(){}; void start(); void tic(); void toc(); void toc(std::string things); void end(); double now(); private: std::chrono::steady_clock::time_point t_s_; //start time ponit std::chrono::steady_clock::time_point t_tic_; //tic time ponit std::chrono::steady_clock::time_point t_toc_; //toc time ponit std::chrono::steady_clock::time_point t_e_; //stop time point }; void Timer::tic() { t_tic_ = std::chrono::steady_clock::now(); } void Timer::toc() { t_toc_ = std::chrono::steady_clock::now(); auto tt = std::chrono::duration_cast>(t_toc_ - t_tic_).count(); std::cout << "Time spend: " << tt << " seconds" << std::endl; } void Timer::toc(std::string things) { t_toc_ = std::chrono::steady_clock::now(); auto tt = std::chrono::duration_cast>(t_toc_ - t_tic_).count(); std::cout << "Time spend: " << tt << " seconds when doing "<>(t_e_ - t_s_).count(); std::cout << "< "<name_<<" > Time total spend: " << tt << " seconds" << std::endl; } double Timer::now() { t_e_ = std::chrono::steady_clock::now(); auto tt = std::chrono::duration_cast>(t_e_ - t_s_).count(); return tt; }