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)
35 Timer(name,
"",
"", 1, 0, 0.0, 0)
39 Timer(name,
"",
"", buf_size, buf_size, 0.0, 0)
43 Timer& operator=(
const Timer& other) =
default;
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(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)
int(* final)(unsigned char *, CTX *)
std::string to_string(ErrorType type)
Convert an ErrorType to string.
double events_per_second() const
double milliseconds() const
Timer(const std::string &name, size_t buf_size)
void set_custom_msg(const std::string &s)
bool operator<(const OID &a, const OID &b)
Timer_Scope(Timer &timer)
const std::string & doing() const
auto run(F f) -> decltype(f())
double seconds_per_event() const
uint64_t cycles_consumed() const
Timer(const std::string &name)
boost::asio::system_timer m_timer
bool under(std::chrono::milliseconds msec)
double ms_per_event() const
const std::string & get_name() const
double bytes_per_second() const
void run_until_elapsed(std::chrono::milliseconds msec, F f)