#ifndef STOPWATCH_H #define STOPWATCH_H #include template class stopwatch { public: void reset(); real elapsed(); private: using clock = std::chrono::high_resolution_clock; clock::time_point t0 { clock::now() }; }; template inline void stopwatch::reset() { t0 = clock::now(); } template inline real stopwatch::elapsed() { using seconds = std::chrono::duration>; auto tnow = clock::now(); auto duration = std::chrono::duration_cast( tnow - t0 ); return duration.count(); } #endif // STOPWATCH_H