vcpkg/toolsrc/include/vcpkg_Chrono.h

32 lines
686 B
C
Raw Normal View History

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 create_started();
2017-02-17 08:29:52 +08:00
constexpr ElapsedTime() : m_start_tick() {}
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_start_tick);
2017-02-17 08:29:52 +08:00
}
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 to_string() const;
2016-10-11 09:12:26 +08:00
private:
std::chrono::high_resolution_clock::time_point m_start_tick;
2016-10-11 09:12:26 +08:00
};
}