23 #include <type_traits>
29 template <
typename TimeT = std::chrono::milliseconds>
31 template <
typename F,
typename... Args>
33 auto start = std::chrono::steady_clock::now();
34 func(std::forward<Args>(
args)...);
36 std::chrono::duration_cast<TimeT>(std::chrono::steady_clock::now() - start);
37 return duration.count();
41 template <
typename Type = std::chrono::steady_clock::time_po
int>
43 return std::chrono::steady_clock::now();
46 template <
typename Type = std::chrono::steady_clock::time_point,
47 typename TypeR = std::chrono::milliseconds>
50 std::chrono::duration_cast<TypeR>(std::chrono::steady_clock::now() - clock_begin);
51 return duration.count();
54 template <
typename TimeT = std::chrono::milliseconds>
66 LOG(
WARNING) <<
" unexpected call to stop on a timer that has not started";
81 timer_stop<std::chrono::steady_clock::time_point, std::chrono::microseconds>;
83 template <
typename Type = std::chrono::steady_clock::time_point,
84 typename TypeR = std::chrono::milliseconds>
86 auto now = std::chrono::steady_clock::now();
87 auto overall_duration = (now - clock_begin);
88 auto since_last_duration = (now - clock_last);
89 auto overall = std::chrono::duration_cast<TypeR>(overall_duration);
90 auto since_last = std::chrono::duration_cast<TypeR>(since_last_duration);
93 std::ostringstream oss;
94 oss << overall.count() <<
" - " << since_last.count();
99 InjectTimer(std::string
const& description,
int const& lineNum, std::string
const& func)
104 <<
" " << std::setw(35) <<
func_ <<
":" << std::setw(5) <<
lineNum_;
111 <<
" " << std::setw(35) <<
func_ <<
":" << std::setw(5) <<
lineNum_
120 std::chrono::steady_clock::time_point
start_;
122 #define INJECT_TIMER(DESC) InjectTimer DESC(#DESC, __LINE__, __FUNCTION__)
124 template <
typename Fn, Fn fn,
typename... Args>
127 return fn(std::forward<Args>(
args)...);
129 #define TIME_WRAP(FUNC) time_wrap<decltype(&FUNC), &FUNC>
131 #endif // _MEASURE_H_
std::chrono::steady_clock::time_point start_
static TimeT::rep execution(F func, Args &&...args)
bool g_enable_debug_timer
TypeR::rep timer_stop(Type clock_begin)
std::string timer_lap(Type clock_begin, Type &clock_last)
const auto timer_stop_microseconds
InjectTimer(std::string const &description, int const &lineNum, std::string const &func)
std::result_of< Fn(Args...)>::type time_wrap(Args...args)
std::chrono::steady_clock::time_point start_time_