polybar/include/utils/time.hpp

24 lines
439 B
C++
Raw Normal View History

2016-11-20 22:04:31 +00:00
#pragma once
#include <chrono>
#include "common.hpp"
POLYBAR_NS
namespace chrono = std::chrono;
namespace time_util {
using clock_t = chrono::high_resolution_clock;
2016-11-22 00:22:47 +00:00
template <typename T, typename Dur = chrono::microseconds>
2016-11-20 22:04:31 +00:00
auto measure(const T& expr) noexcept {
auto start = clock_t::now();
expr();
auto finish = clock_t::now();
return chrono::duration_cast<Dur>(finish - start).count();
}
}
POLYBAR_NS_END