10#include <botan/types.h>
20 const std::string& provider,
21 const std::string& doing,
24 double clock_cycle_ratio,
26 : m_name(
name + ((provider.empty() || provider ==
"base") ?
"" :
" [" + provider +
"]"))
28 , m_buf_size(buf_size)
29 , m_event_mult(event_mult)
30 , m_clock_cycle_ratio(clock_cycle_ratio)
31 , m_clock_speed(clock_speed)
39 Timer(
name,
"",
"", buf_size, buf_size, 0.0, 0)
49 bool under(std::chrono::milliseconds msec)
51 return (milliseconds() < msec.count());
75 auto run(F f) ->
decltype(f())
84 while(this->under(msec))
97 return milliseconds() / 1000.0;
102 return value() / 1000000.0;
107 return milliseconds() / events();
112 if(m_clock_speed != 0)
114 return static_cast<uint64_t
>((m_clock_speed * value()) / 1000.0);
116 return m_cpu_cycles_used;
121 return m_event_count * m_event_mult;
141 return seconds() > 0.0 ? events() / seconds() : 0.0;
146 return seconds() > 0.0 ? events() / seconds() : 0.0;
151 return events() > 0 ? seconds() / events() : 0.0;
164 std::string result_string_bps()
const;
165 std::string result_string_ops()
const;
168 std::string m_name, m_doing;
170 uint64_t m_event_mult;
171 double m_clock_cycle_ratio;
172 uint64_t m_clock_speed;
175 std::string m_custom_msg;
176 uint64_t m_time_used = 0, m_timer_start = 0;
177 uint64_t m_event_count = 0;
179 uint64_t m_max_time = 0, m_min_time = 0;
180 uint64_t m_cpu_cycles_start = 0, m_cpu_cycles_used = 0;
Timer_Scope(Timer &timer)
Timer(const std::string &name, size_t buf_size)
double milliseconds() const
double events_per_second() const
Timer(const std::string &name)
bool under(std::chrono::milliseconds msec)
uint64_t cycles_consumed() const
Timer & operator=(const Timer &other)=default
double ms_per_event() const
double seconds_per_event() const
void set_custom_msg(const std::string &s)
auto run(F f) -> decltype(f())
Timer(const Timer &other)=default
Timer(const std::string &name, const std::string &provider, const std::string &doing, uint64_t event_mult, size_t buf_size, double clock_cycle_ratio, uint64_t clock_speed)
const std::string & get_name() const
const std::string & doing() const
void run_until_elapsed(std::chrono::milliseconds msec, F f)
double bytes_per_second() const
int(* final)(unsigned char *, CTX *)
bool operator<(const OID &a, const OID &b)
std::string to_string(ErrorType type)
Convert an ErrorType to string.