vcpkg/toolsrc/include/vcpkg_Chrono.h

29 lines
657 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>
2017-02-17 08:29:52 +08:00
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
}
double microseconds() const { 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
};
}