Skip to content
Snippets Groups Projects
Commit 9be59975 authored by Armin Co's avatar Armin Co
Browse files

Timer class for profiling

parent 4d3498eb
Branches
No related tags found
No related merge requests found
/// @file Timer.cpp
/// @author Armin Co
///
#include "Timer.hpp"
#include "Log.hpp"
using namespace GuiCore;
Timer::Timer(const char* name)
: m_name{name}
{
m_startTimepoint = std::chrono::high_resolution_clock::now();
}
Timer::~Timer()
{
stop();
}
double Timer::stop()
{
auto endTimepoint = std::chrono::high_resolution_clock::now();
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(m_startTimepoint).time_since_epoch().count();
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch().count();
auto duration = end - start;
double ms = duration * 0.001;
Log::get()->debug("{0}: {1}ms", m_name, ms);
return ms;
}
\ No newline at end of file
/// @file Timer.hpp
/// @author Armmin Co
///
#ifndef GUI_CORE_TIMER_HPP
#define GUI_CORE_TIMER_HPP
#include <chrono>
namespace GuiCore
{
class Timer
{
public:
/// @brief Start timer
///
Timer(const char* name = "Timer");
/// @brief Stops timer.
~Timer();
double stop();
private:
std::chrono::time_point< std::chrono::high_resolution_clock > m_startTimepoint;
const char* m_name;
};
}
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment