2016-10-11 09:12:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
2017-02-17 08:29:52 +08:00
|
|
|
class ElapsedTime
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static ElapsedTime createStarted();
|
|
|
|
|
|
|
|
constexpr ElapsedTime() :m_startTick() {}
|
|
|
|
|
|
|
|
template <class TimeUnit>
|
|
|
|
TimeUnit elapsed() const
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<TimeUnit>(std::chrono::high_resolution_clock::now() - this->m_startTick);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string toString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::chrono::steady_clock::time_point m_startTick;
|
|
|
|
};
|
|
|
|
|
2016-10-11 09:12:26 +08:00
|
|
|
class Stopwatch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Stopwatch createUnstarted();
|
|
|
|
|
|
|
|
static Stopwatch createStarted();
|
|
|
|
|
|
|
|
bool isRunning() const;
|
|
|
|
|
2016-10-11 14:57:43 +08:00
|
|
|
const Stopwatch& start();
|
2016-10-11 09:12:26 +08:00
|
|
|
|
2016-10-11 14:57:43 +08:00
|
|
|
const Stopwatch& stop();
|
2016-10-11 09:12:26 +08:00
|
|
|
|
|
|
|
Stopwatch& reset();
|
|
|
|
|
|
|
|
template <class TimeUnit>
|
|
|
|
TimeUnit elapsed() const
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<TimeUnit>(elapsedNanos());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string toString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Stopwatch();
|
|
|
|
|
|
|
|
std::chrono::nanoseconds elapsedNanos() const;
|
|
|
|
|
|
|
|
bool m_isRunning;
|
|
|
|
std::chrono::nanoseconds m_elapsedNanos;
|
|
|
|
std::chrono::steady_clock::time_point m_startTick;
|
|
|
|
};
|
|
|
|
}
|