19 std::string_view provider,
20 std::string_view doing,
23 double clock_cycle_ratio,
24 uint64_t clock_speed);
28 Timer(std::string_view
name,
size_t buf_size) :
Timer(
name,
"",
"", buf_size, buf_size, 0.0, 0) {}
37 bool under(std::chrono::milliseconds msec)
const {
return (milliseconds() < msec.count()); }
54 auto run(F f) ->
decltype(f()) {
61 while(this->under(msec)) {
66 uint64_t
value()
const {
return m_time_used; }
68 double seconds()
const {
return milliseconds() / 1000.0; }
75 if(m_clock_speed != 0) {
76 return static_cast<uint64_t
>((m_clock_speed * value()) / 1000.0);
78 return m_cpu_cycles_used;
81 uint64_t
events()
const {
return m_event_count * m_event_mult; }
83 const std::string&
get_name()
const {
return m_name; }
85 const std::string&
doing()
const {
return m_doing; }
89 double bytes_per_second()
const {
return seconds() > 0.0 ? events() / seconds() : 0.0; }
99 std::string to_string()
const;
102 std::string result_string_bps()
const;
103 std::string result_string_ops()
const;
106 std::string m_name, m_doing;
108 uint64_t m_event_mult;
109 double m_clock_cycle_ratio;
110 uint64_t m_clock_speed;
113 std::string m_custom_msg;
114 uint64_t m_event_count = 0;
116 uint64_t m_time_used = 0;
117 uint64_t m_timer_start = 0;
119 uint64_t m_cpu_cycles_used = 0;
120 uint64_t m_cpu_cycles_start = 0;