1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00

feat(debug_util): Scoped execution timer

This commit is contained in:
Michael Carlberg 2016-12-16 04:01:23 +01:00
parent 1d53e7f454
commit d94d8ccfd3

View file

@ -12,11 +12,26 @@
POLYBAR_NS POLYBAR_NS
namespace debug_util { namespace debug_util {
template <class T> /**
void loop(const T& expr, size_t iterations) noexcept { * Wrapper that starts tracking the time when created
while (iterations--) { * and reports the duration when it goes out of scope
expr(); */
class scope_timer {
public:
using clock_t = std::chrono::high_resolution_clock;
using duration_t = std::chrono::milliseconds;
explicit scope_timer() : m_start(clock_t::now()) {}
~scope_timer() {
std::cout << std::chrono::duration_cast<duration_t>(clock_t::now() - m_start).count() << "ms" << std::endl;
} }
private:
clock_t::time_point m_start;
};
inline unique_ptr<scope_timer> make_scope_timer() {
return make_unique<scope_timer>();
} }
template <class T> template <class T>
@ -28,11 +43,6 @@ namespace debug_util {
<< "ms" << std::endl; << "ms" << std::endl;
} }
template <class T>
void execution_speed(const T& expr, size_t iterations) noexcept {
execution_speed([=] { loop(expr, iterations); });
}
template <class T> template <class T>
void memory_usage(const T& object) noexcept { void memory_usage(const T& object) noexcept {
std::cout << "memory usage: " << sizeof(object) << "b" << std::endl; std::cout << "memory usage: " << sizeof(object) << "b" << std::endl;