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:
|
2017-04-04 06:44:46 +08:00
|
|
|
static ElapsedTime create_started();
|
2017-02-17 08:29:52 +08:00
|
|
|
|
2017-04-04 06:44:46 +08:00
|
|
|
constexpr ElapsedTime() : m_start_tick() {}
|
2017-02-17 08:29:52 +08:00
|
|
|
|
2017-04-28 08:56:06 +08:00
|
|
|
template<class TimeUnit>
|
2017-02-17 08:29:52 +08:00
|
|
|
TimeUnit elapsed() const
|
|
|
|
{
|
2017-04-04 06:44:46 +08:00
|
|
|
return std::chrono::duration_cast<TimeUnit>(std::chrono::high_resolution_clock::now() - this->m_start_tick);
|
2017-02-17 08:29:52 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 08:56:06 +08:00
|
|
|
double microseconds() const { return elapsed<std::chrono::duration<double, std::micro>>().count(); }
|
2016-10-11 09:12:26 +08:00
|
|
|
|
2017-04-04 06:44:46 +08:00
|
|
|
std::string to_string() const;
|
2016-10-11 09:12:26 +08:00
|
|
|
|
|
|
|
private:
|
2017-04-04 06:44:46 +08:00
|
|
|
std::chrono::high_resolution_clock::time_point m_start_tick;
|
2016-10-11 09:12:26 +08:00
|
|
|
};
|
|
|
|
}
|