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 Type = std::chrono::steady_clock::time_point,
55 typename TypeR = std::chrono::milliseconds>
57 auto now = std::chrono::steady_clock::now();
58 auto overall_duration = (now - clock_begin);
59 auto since_last_duration = (now - clock_last);
60 auto overall = std::chrono::duration_cast<TypeR>(overall_duration);
61 auto since_last = std::chrono::duration_cast<TypeR>(since_last_duration);
64 std::ostringstream oss;
65 oss << overall.count() <<
" - " << since_last.count();
70 InjectTimer(std::string
const& description,
int const& lineNum, std::string
const& func)
75 <<
" " << std::setw(35) <<
func_ <<
":" << std::setw(5) <<
lineNum_;
82 <<
" " << std::setw(35) <<
func_ <<
":" << std::setw(5) <<
lineNum_
91 std::chrono::steady_clock::time_point
start_;
93 #define INJECT_TIMER(DESC) InjectTimer DESC(#DESC, __LINE__, __FUNCTION__)
95 template <
typename Fn, Fn fn,
typename... Args>
98 return fn(std::forward<Args>(
args)...);
100 #define TIME_WRAP(FUNC) time_wrap<decltype(&FUNC), &FUNC>
102 #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)
InjectTimer(std::string const &description, int const &lineNum, std::string const &func)
std::result_of< Fn(Args...)>::type time_wrap(Args...args)