Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Member Functions | List of all members
Botan::Timer Class Referencefinal

`#include <timer.h>`

## Classes
class | Timer_Scope

## Public Member Functions
size_t | buf_size () const
double | bytes_per_second () const
uint64_t | cycles_consumed () const
const std::string & | doing () const
uint64_t | events () const
double | events_per_second () const
const std::string & | get_name () const
double | milliseconds () const
double | ms_per_event () const
bool | operator< (const Timer &other) const
Timer & | operator= (const Timer &other)=default
template<typename F >
auto | run (F f) -> decltype(f())
template<typename F >
void | run_until_elapsed (std::chrono::milliseconds msec, F f)
double | seconds () const
double | seconds_per_event () const
void | set_custom_msg (const std::string &s)
void | start ()
void | stop ()
| 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)
| Timer (const std::string &name)
| Timer (const std::string &name, size_t buf_size)
| Timer (const Timer &other)=default
std::string | to_string () const
bool | under (std::chrono::milliseconds msec)
uint64_t | value () const

## Detailed Description

Definition at line 16 of file timer.h.

## Constructor & Destructor Documentation

Botan::Timer::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
| ) |  |
| inline

Definition at line 19 of file timer.h.

26 : m_name(name + ((provider.empty() || provider == "base") ? "" : " [" + provider + "]"))
27 , m_doing(doing)
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)
32 {}
Botan::Timer::buf_size
size_t buf_size() const
Definition: timer.h:134
name
std::string name
Definition: commoncrypto_hash.cpp:23
Botan::Timer::doing
const std::string & doing() const
Definition: timer.h:129

Botan::Timer::Timer | ( | const std::string & | name | ) |
| inline

Definition at line 34 of file timer.h.

34 :
35 Timer(name, "", "", 1, 0, 0.0, 0)
36 {}
Botan::Timer::Timer
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)
Definition: timer.h:19
name
std::string name
Definition: commoncrypto_hash.cpp:23

Botan::Timer::Timer | ( | const std::string & | name,
|  | size_t | buf_size
| ) |  |
| inline

Definition at line 38 of file timer.h.

38 :
39 Timer(name, "", "", buf_size, buf_size, 0.0, 0)
40 {}
Botan::Timer::Timer
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)
Definition: timer.h:19
Botan::Timer::buf_size
size_t buf_size() const
Definition: timer.h:134
name
std::string name
Definition: commoncrypto_hash.cpp:23

Botan::Timer::Timer | ( | const Timer & | other | ) |
| default

## Member Function Documentation

size_t Botan::Timer::buf_size | ( |  | ) | const
| inline

Definition at line 134 of file timer.h.

Referenced by to_string().

135 {
136 return m_buf_size;
137 }

double Botan::Timer::bytes_per_second | ( |  | ) | const
| inline

Definition at line 139 of file timer.h.

Referenced by Botan::RFC4880_S2K_Family::tune().

140 {
141 return seconds() > 0.0 ? events() / seconds() : 0.0;
142 }
Botan::Timer::seconds
double seconds() const
Definition: timer.h:95
Botan::Timer::events
uint64_t events() const
Definition: timer.h:119

uint64_t Botan::Timer::cycles_consumed | ( |  | ) | const
| inline

Definition at line 110 of file timer.h.

111 {
112 if(m_clock_speed != 0)
113 {
114 return static_cast<uint64_t>((m_clock_speed * value()) / 1000.0);
115 }
116 return m_cpu_cycles_used;
117 }
Botan::Timer::value
uint64_t value() const
Definition: timer.h:90

const std::string& Botan::Timer::doing | ( |  | ) | const
| inline

Definition at line 129 of file timer.h.

Referenced by operator<().

130 {
131 return m_doing;
132 }

uint64_t Botan::Timer::events | ( |  | ) | const
| inline

Definition at line 119 of file timer.h.

Referenced by Botan::Bcrypt_PBKDF_Family::tune(), Botan::Scrypt_Family::tune(), and Botan::Argon2_Family::tune().

120 {
121 return m_event_count * m_event_mult;
122 }

double Botan::Timer::events_per_second | ( |  | ) | const
| inline

Definition at line 144 of file timer.h.

145 {
146 return seconds() > 0.0 ? events() / seconds() : 0.0;
147 }
Botan::Timer::seconds
double seconds() const
Definition: timer.h:95
Botan::Timer::events
uint64_t events() const
Definition: timer.h:119

const std::string& Botan::Timer::get_name | ( |  | ) | const
| inline

Definition at line 124 of file timer.h.

References m_name.

Referenced by operator<().

125 {
126 return m_name;
127 }

double Botan::Timer::milliseconds | ( |  | ) | const
| inline

Definition at line 100 of file timer.h.

101 {
102 return value() / 1000000.0;
103 }
Botan::Timer::value
uint64_t value() const
Definition: timer.h:90

double Botan::Timer::ms_per_event | ( |  | ) | const
| inline

Definition at line 105 of file timer.h.

106 {
107 return milliseconds() / events();
108 }
Botan::Timer::events
uint64_t events() const
Definition: timer.h:119
Botan::Timer::milliseconds
double milliseconds() const
Definition: timer.h:100

bool Botan::Timer::operator< | ( | const Timer & | other | ) | const

Definition at line 59 of file timer.cpp.

References doing(), and get_name().

60 {
61 if(this->doing() != other.doing())
62 return (this->doing() < other.doing());
63
64 return (this->get_name() < other.get_name());
65 }
Botan::Timer::doing
const std::string & doing() const
Definition: timer.h:129
Botan::Timer::get_name
const std::string & get_name() const
Definition: timer.h:124

Timer& Botan::Timer::operator= | ( | const Timer & | other | ) |
| default

template<typename F >

auto Botan::Timer::run | ( | F | f | ) | -> decltype(f())
| inline

Definition at line 75 of file timer.h.

76 {
77 Timer_Scope timer(*this);
78 return f();
79 }
template<typename F >

void Botan::Timer::run_until_elapsed | ( | std::chrono::milliseconds | msec,
|  | F | f
| ) |  |
| inline

Definition at line 82 of file timer.h.

Referenced by Botan::Bcrypt_PBKDF_Family::tune(), Botan::Scrypt_Family::tune(), Botan::Argon2_Family::tune(), and Botan::RFC4880_S2K_Family::tune().

83 {
84 while(this->under(msec))
85 {
86 run(f);
87 }
88 }
Botan::Timer::run
auto run(F f) -> decltype(f())
Definition: timer.h:75
Botan::Timer::under
bool under(std::chrono::milliseconds msec)
Definition: timer.h:49

double Botan::Timer::seconds | ( |  | ) | const
| inline

Definition at line 95 of file timer.h.

96 {
97 return milliseconds() / 1000.0;
98 }
Botan::Timer::milliseconds
double milliseconds() const
Definition: timer.h:100

double Botan::Timer::seconds_per_event | ( |  | ) | const
| inline

Definition at line 149 of file timer.h.

150 {
151 return events() > 0 ? seconds() / events() : 0.0;
152 }
Botan::Timer::seconds
double seconds() const
Definition: timer.h:95
Botan::Timer::events
uint64_t events() const
Definition: timer.h:119

void Botan::Timer::set_custom_msg | ( | const std::string & | s | ) |
| inline

Definition at line 154 of file timer.h.

155 {
156 m_custom_msg = s;
157 }

void Botan::Timer::start | ( |  | ) |

Definition at line 15 of file timer.cpp.

References Botan::OS::get_cpu_cycle_counter(), Botan::OS::get_system_timestamp_ns(), and stop().

16 {
17 stop();
18 m_timer_start = OS::get_system_timestamp_ns();
19 m_cpu_cycles_start = OS::get_cpu_cycle_counter();
20 }
Botan::OS::get_cpu_cycle_counter
uint64_t BOTAN_TEST_API get_cpu_cycle_counter()
Definition: os_utils.cpp:154
Botan::OS::get_system_timestamp_ns
uint64_t BOTAN_TEST_API get_system_timestamp_ns()
Definition: os_utils.cpp:293
Botan::Timer::stop
void stop()
Definition: timer.cpp:22

void Botan::Timer::stop | ( |  | ) |

Definition at line 22 of file timer.cpp.

References Botan::OS::get_cpu_cycle_counter(), and Botan::OS::get_system_timestamp_ns().

Referenced by start().

23 {
24 if(m_timer_start)
25 {
26 if(m_cpu_cycles_start != 0)
27 {
28 const uint64_t cycles_taken = OS::get_cpu_cycle_counter() - m_cpu_cycles_start;
29 if(cycles_taken > 0)
30 {
31 m_cpu_cycles_used += static_cast<size_t>(cycles_taken * m_clock_cycle_ratio);
32 }
33 }
34
35 const uint64_t now = OS::get_system_timestamp_ns();
36
37 if(now > m_timer_start)
38 {
39 const uint64_t dur = now - m_timer_start;
40
41 m_time_used += dur;
42
43 if(m_event_count == 0)
44 {
45 m_min_time = m_max_time = dur;
46 }
47 else
48 {
49 m_max_time = std::max(m_max_time, dur);
50 m_min_time = std::min(m_min_time, dur);
51 }
52 }
53
54 m_timer_start = 0;
55 ++m_event_count;
56 }
57 }
Botan::OS::get_cpu_cycle_counter
uint64_t BOTAN_TEST_API get_cpu_cycle_counter()
Definition: os_utils.cpp:154
Botan::OS::get_system_timestamp_ns
uint64_t BOTAN_TEST_API get_system_timestamp_ns()
Definition: os_utils.cpp:293

std::string Botan::Timer::to_string | ( |  | ) | const

Definition at line 67 of file timer.cpp.

References buf_size().

68 {
69 if(m_custom_msg.size() > 0)
70 {
71 return m_custom_msg;
72 }
73 else if(this->buf_size() == 0)
74 {
75 return result_string_ops();
76 }
77 else
78 {
79 return result_string_bps();
80 }
81 }
Botan::Timer::buf_size
size_t buf_size() const
Definition: timer.h:134

bool Botan::Timer::under | ( | std::chrono::milliseconds | msec | ) |
| inline

Definition at line 49 of file timer.h.

50 {
51 return (milliseconds() < msec.count());
52 }
Botan::Timer::milliseconds
double milliseconds() const
Definition: timer.h:100

uint64_t Botan::Timer::value | ( |  | ) | const
| inline

Definition at line 90 of file timer.h.

Referenced by Botan::Bcrypt_PBKDF_Family::tune(), Botan::Scrypt_Family::tune(), and Botan::Argon2_Family::tune().

91 {
92 return m_time_used;
93 }

The documentation for this class was generated from the following files:

- src/lib/utils/timer.h
- src/lib/utils/timer.cpp