New file |
| | |
| | | #pragma once |
| | | |
| | | #include <istream> |
| | | #include <string> |
| | | #include <chrono> |
| | | #include "log_util.h" |
| | | #include <boost/format.hpp> |
| | | |
| | | class Timer |
| | | { |
| | | public: |
| | | Timer():beg_(clock_::now()){} |
| | | void reset() |
| | | { |
| | | beg_ = clock_::now(); |
| | | } |
| | | double elapsed() const |
| | | { |
| | | return std::chrono::duration_cast<second_>(clock_::now() - beg_).count(); |
| | | } |
| | | void out(std::string message="") |
| | | { |
| | | double t = elapsed(); |
| | | // std::cout << message << " elasped time:" << t << "ms" << std::endl; |
| | | DEBUG((boost::format("%e lasped time:%f ms")%message %t).str()); |
| | | reset(); |
| | | } |
| | | // DEBUG((boost::format("nhao%d")%1).str()); |
| | | |
| | | double get_duration() const |
| | | { |
| | | return elapsed(); |
| | | } |
| | | private: |
| | | using clock_ = std::chrono::high_resolution_clock; |
| | | using second_=std::chrono::duration<double,std::milli>; |
| | | std::chrono::time_point<clock_>beg_; |
| | | }; |