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();
|
|
|
|
|
2017-03-04 22:25:05 +08:00
|
|
|
constexpr ElapsedTime() : m_startTick() {}
|
2017-02-17 08:29:52 +08:00
|
|
|
|
|
|
|
template <class TimeUnit>
|
|
|
|
TimeUnit elapsed() const
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<TimeUnit>(std::chrono::high_resolution_clock::now() - this->m_startTick);
|
|
|
|
}
|
|
|
|
|
2017-03-04 22:25:05 +08:00
|
|
|
double microseconds() const
|
2016-10-11 09:12:26 +08:00
|
|
|
{
|
2017-03-04 22:25:05 +08:00
|
|
|
return elapsed<std::chrono::duration<double, std::micro>>().count();
|
2016-10-11 09:12:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string toString() const;
|
|
|
|
|
|
|
|
private:
|
2017-03-04 22:25:05 +08:00
|
|
|
std::chrono::high_resolution_clock::time_point m_startTick;
|
2016-10-11 09:12:26 +08:00
|
|
|
};
|
|
|
|
}
|