7#include <botan/internal/timer.h>
8#include <botan/internal/os_utils.h>
26 if(m_cpu_cycles_start != 0)
31 m_cpu_cycles_used +=
static_cast<size_t>(cycles_taken * m_clock_cycle_ratio);
37 if(now > m_timer_start)
39 const uint64_t dur = now - m_timer_start;
43 if(m_event_count == 0)
45 m_min_time = m_max_time = dur;
49 m_max_time = std::max(m_max_time, dur);
50 m_min_time = std::min(m_min_time, dur);
69 if(m_custom_msg.size() > 0)
75 return result_string_ops();
79 return result_string_bps();
83std::string Timer::result_string_bps()
const
85 const size_t MiB = 1024 * 1024;
87 const double MiB_total =
static_cast<double>(
events()) / MiB;
88 const double MiB_per_sec = MiB_total /
seconds();
90 std::ostringstream oss;
95 oss <<
" " <<
doing();
100 oss <<
" buffer size " <<
buf_size() <<
" bytes:";
106 oss <<
" " << std::fixed << std::setprecision(3) << MiB_per_sec <<
" MiB/sec";
111 oss <<
" " << std::fixed << std::setprecision(2) << cycles_per_byte <<
" cycles/byte";
114 oss <<
" (" << MiB_total <<
" MiB in " <<
milliseconds() <<
" ms)\n";
119std::string Timer::result_string_ops()
const
121 std::ostringstream oss;
127 oss <<
"no events\n";
132 <<
' ' <<
doing() <<
"/sec; "
133 << std::setprecision(2) << std::fixed
139 const int precision = (cycles_per_op < 10000) ? 2 : 0;
140 oss <<
" " << std::fixed << std::setprecision(precision) << cycles_per_op <<
" cycles/op";
143 oss <<
" (" <<
events() <<
" " << (
events() == 1 ?
"op" :
"ops")
bool operator<(const Timer &other) const
double milliseconds() const
double events_per_second() const
uint64_t cycles_consumed() const
double ms_per_event() const
std::string to_string() const
const std::string & get_name() const
const std::string & doing() const
uint64_t BOTAN_TEST_API get_system_timestamp_ns()
uint64_t BOTAN_TEST_API get_cpu_cycle_counter()