You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
807 B

#pragma once
#include <chrono>
#include <string>
#include <iostream>
class Timer
{
private:
std::chrono::steady_clock::time_point m_begin;
std::chrono::steady_clock::time_point m_end;
std::string m_name;
public:
Timer(std::string name) : m_name(std::move(name)) { m_begin = std::chrono::steady_clock::now(); }
void restart() { m_begin = std::chrono::steady_clock::now(); }
void rename(std::string name)
{
m_name = std::move(name);
m_begin = std::chrono::steady_clock::now();
}
void stop()
{
m_end = std::chrono::steady_clock::now();
double duration = std::chrono::duration<double>(m_end - m_begin).count();
std::cout << m_name << " duration: " << duration << "s" << std::endl;
}
};