2022-02-24 22:48:39 -05:00
|
|
|
#include "EventTimer.hpp"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
using namespace std::string_literals;
|
2022-10-24 18:39:33 +08:00
|
|
|
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
//| Function - EventTimer::EventTimer()
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
//| Purpose - Return current time point in frame of the high resolution clock
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
EventTimer::EventTimer()
|
|
|
|
|
{
|
2022-02-24 22:48:39 -05:00
|
|
|
_now = std::chrono::high_resolution_clock::now();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 18:39:33 +08:00
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
//| Function - EventTimer::Elapsed()
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
//| Purpose - Return elapsed time since EventTimer was started
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
auto EventTimer::Elapsed( bool reset ) -> long long
|
|
|
|
|
{
|
|
|
|
|
auto delta = std::chrono::high_resolution_clock::now() - _now;
|
|
|
|
|
if( reset )
|
|
|
|
|
{
|
|
|
|
|
_now = std::chrono::high_resolution_clock::now();
|
2022-02-25 09:44:11 -05:00
|
|
|
}
|
2022-10-24 18:39:33 +08:00
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>( delta ).count();
|
2022-02-24 22:48:39 -05:00
|
|
|
}
|
|
|
|
|
|
2022-10-24 18:39:33 +08:00
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
//| Function - EventTimer::output()
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
//| Purpose - Output the elapsed time to console
|
|
|
|
|
//o------------------------------------------------------------------------------------------------o
|
|
|
|
|
auto EventTimer::Output( const std::string &label = "Delta from last call", bool reset ) -> void
|
|
|
|
|
{
|
|
|
|
|
std::cout << label << " - "s << Elapsed( reset ) << "(ms)\n"s;
|
2022-02-24 22:48:39 -05:00
|
|
|
}
|