geekbrains_gof/SBomber/include/Timer.h

47 lines
814 B
C
Raw Permalink Normal View History

2021-12-20 23:33:45 +00:00
/*
* Timer.h
*
* Created on: 21 дек. 2021 г.
* Author: alexander
*/
#pragma once
#include <chrono>
class Timer
{
public:
static Timer& getInstance()
{
static Timer _instance;
return _instance;
}
void start()
{
m_beg = clock_t::now();
}
double end() const
{
return elapsed() * 1000;
}
private:
using clock_t = std::chrono::high_resolution_clock;
using second_t = std::chrono::duration<double, std::ratio<1> >;
std::chrono::time_point<clock_t> m_beg;
double elapsed() const
{
return std::chrono::duration_cast<second_t>(clock_t::now() - m_beg).count();
}
Timer() {}
Timer(const Timer&) = delete;
Timer& operator=(const Timer&) = delete;
Timer& operator=(Timer&&) = delete;
};