2016-06-14 23:32:35 -04:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-15 11:14:56 -05:00
|
|
|
#ifndef DEBUG
|
|
|
|
#error "Not a debug build..."
|
|
|
|
#endif
|
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
#include <chrono>
|
2016-11-25 02:42:31 -05:00
|
|
|
#include <iostream>
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-15 11:14:56 -05:00
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-15 11:14:56 -05:00
|
|
|
namespace debug_util {
|
2016-12-15 22:01:23 -05:00
|
|
|
/**
|
|
|
|
* 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<duration_t>(clock_t::now() - m_start).count() << "ms" << std::endl;
|
2016-12-15 11:14:56 -05:00
|
|
|
}
|
2016-12-15 22:01:23 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
clock_t::time_point m_start;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline unique_ptr<scope_timer> make_scope_timer() {
|
|
|
|
return make_unique<scope_timer>();
|
2016-12-15 11:14:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void execution_speed(const T& expr) noexcept {
|
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
expr();
|
|
|
|
auto finish = std::chrono::high_resolution_clock::now();
|
|
|
|
std::cout << "execution speed: " << std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count()
|
|
|
|
<< "ms" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void memory_usage(const T& object) noexcept {
|
|
|
|
std::cout << "memory usage: " << sizeof(object) << "b" << std::endl;
|
|
|
|
}
|
2016-06-14 23:32:35 -04:00
|
|
|
}
|
|
|
|
|
2016-12-15 11:14:56 -05:00
|
|
|
POLYBAR_NS_END
|