// https://stackoverflow.com/questions/31905157/how-to-print-the-execution-time-of-my-code #ifndef TIMER_HPP #define TIMER_HPP #include #include #include #include #include namespace my{ class Timer { using clk = std::chrono::steady_clock; //using clk = std::chrono::high_resolution_clock; clk::time_point b; // begin clk::time_point e; // end double secs(void) const{ if(e <= b) return 0.0; auto d = std::chrono::duration_cast(e - b); return d.count() / 1000000.0; } public: void clear(void) { b = e = clk::now(); } void start(void) { b = clk::now(); } void stop(void) { e = clk::now(); } void tic(void) {start();} void toc(void) {stop();} void tocs(std::ostream &o=std::cout) {stop(); o << secs()<<" s\n";} friend std::ostream& operator<<(std::ostream &o , const Timer &timer) { return o << timer.secs(); } }; } #endif