diff --git a/include/debug.hpp b/include/debug.hpp index 35b6b43f..59892f56 100644 --- a/include/debug.hpp +++ b/include/debug.hpp @@ -12,11 +12,26 @@ POLYBAR_NS namespace debug_util { - template - void loop(const T& expr, size_t iterations) noexcept { - while (iterations--) { - expr(); + /** + * Wrapper that starts tracking the time when created + * and reports the duration when it goes out of scope + */ + 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(clock_t::now() - m_start).count() << "ms" << std::endl; } + + private: + clock_t::time_point m_start; + }; + + inline unique_ptr make_scope_timer() { + return make_unique(); } template @@ -28,11 +43,6 @@ namespace debug_util { << "ms" << std::endl; } - template - void execution_speed(const T& expr, size_t iterations) noexcept { - execution_speed([=] { loop(expr, iterations); }); - } - template void memory_usage(const T& object) noexcept { std::cout << "memory usage: " << sizeof(object) << "b" << std::endl;