geekbrains_gof/SBomber/include/Timer.h

47 lines
814 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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;
};