#include "timer.h" #include "logfacility.h" namespace Pol { namespace Tools { void DebugT::print( const std::string& name, long long time ) { INFO_PRINTLN( "\n----------------------------------\n" "{}: {} ms" "\n----------------------------------", name, time ); } void SilentT::print( const std::string&, long long ) {} template Timer::Timer( std::string name ) : _name( std::move( name ) ) { start(); } template Timer::Timer() : _name( "" ) { start(); } template Timer::~Timer() { if ( _start == _end ) stop(); printer::print( _name, ellapsed() ); } template void Timer::start() { _start = _end = Clock::now(); } template void Timer::stop() { _end = Clock::now(); } template long long Timer::ellapsed() const { Clock::time_point _now = Clock::now(); if ( _start != _end ) // already stopped _now = _end; return std::chrono::duration_cast( _now - _start ).count(); } template double Timer::ellapsed_s() const { return ellapsed() * static_cast( ms::period::num ) / ms::period::den; } template void Timer::print() const { DebugT::print( _name, ellapsed() ); } HighPerfTimer::HighPerfTimer() : _start( Clock::now() ) {} HighPerfTimer::time_mu HighPerfTimer::ellapsed() const { Clock::time_point _now = Clock::now(); return std::chrono::duration_cast( _now - _start ); } // forward declarce both versions template class Timer; template class Timer; } // namespace Tools } // namespace Pol