• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 13219613470

08 Feb 2025 08:36PM UTC coverage: 91.658% (+0.004%) from 91.654%
13219613470

push

github

web-flow
Merge pull request #4650 from randombit/jack/header-minimization

Reorganize code and reduce header dependencies

94839 of 103471 relevant lines covered (91.66%)

11134372.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/src/cli/perf.h
1
/*
2
* (C) 2024 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#ifndef BOTAN_CLI_PERF_H_
8
#define BOTAN_CLI_PERF_H_
9

10
#include <botan/rng.h>
11
#include <botan/internal/fmt.h>
12
#include <chrono>
13
#include <functional>
14
#include <iosfwd>
15
#include <map>
16
#include <memory>
17
#include <string>
18

19
#include "timer.h"
20

21
namespace Botan_CLI {
22

23
class PerfConfig final {
24
   public:
25
      PerfConfig(std::function<void(const Timer&)> record_result,
25✔
26
                 size_t clock_speed,
27
                 double clock_cycle_ratio,
28
                 std::chrono::milliseconds runtime,
29
                 const std::vector<std::string>& ecc_groups,
30
                 const std::vector<size_t>& buffer_sizes,
31
                 std::ostream& error_output,
32
                 Botan::RandomNumberGenerator& rng) :
25✔
33
            m_record_result(std::move(record_result)),
25✔
34
            m_clock_speed(clock_speed),
25✔
35
            m_clock_cycle_ratio(clock_cycle_ratio),
25✔
36
            m_runtime(runtime),
25✔
37
            m_ecc_groups(ecc_groups),
25✔
38
            m_buffer_sizes(buffer_sizes),
25✔
39
            m_error_output(error_output),
25✔
40
            m_rng(rng) {}
25✔
41

42
      const std::vector<size_t>& buffer_sizes() const { return m_buffer_sizes; }
15✔
43

44
      const std::vector<std::string>& ecc_groups() const { return m_ecc_groups; }
6✔
45

46
      std::chrono::milliseconds runtime() const { return m_runtime; }
261✔
47

48
      std::ostream& error_output() const { return m_error_output; }
×
49

50
      Botan::RandomNumberGenerator& rng() const { return m_rng; }
10,035✔
51

52
      void record_result(const Timer& timer) const { m_record_result(timer); }
777✔
53

54
      std::unique_ptr<Timer> make_timer(const std::string& alg,
495✔
55
                                        uint64_t event_mult = 1,
56
                                        const std::string& what = "",
57
                                        const std::string& provider = "",
58
                                        size_t buf_size = 0) const {
59
         return std::make_unique<Timer>(alg, provider, what, event_mult, buf_size, m_clock_cycle_ratio, m_clock_speed);
495✔
60
      }
61

62
   private:
63
      std::function<void(const Timer&)> m_record_result;
64
      size_t m_clock_speed = 0;
65
      double m_clock_cycle_ratio = 0.0;
66
      std::chrono::milliseconds m_runtime;
67
      std::vector<std::string> m_ecc_groups;
68
      std::vector<size_t> m_buffer_sizes;
69
      std::ostream& m_error_output;
70
      Botan::RandomNumberGenerator& m_rng;
71
};
72

73
class PerfTest {
45✔
74
   public:
75
      virtual ~PerfTest() = default;
76

77
      // Returns nullptr if unknown / not available
78
      static std::unique_ptr<PerfTest> get(const std::string& alg);
79

80
      virtual void go(const PerfConfig& config) = 0;
81

82
      virtual std::string format_name(const std::string& alg, const std::string& param) const;
83

84
      typedef std::function<std::unique_ptr<PerfTest>()> pt_maker_fn;
85

86
      class Registration final {
87
         public:
88
            Registration(const std::string& name, const std::function<std::unique_ptr<PerfTest>()>& maker_fn);
89
      };
90

91
   private:
92
      static std::unique_ptr<PerfTest> get_sym(const std::string& alg);
93

94
      static std::map<std::string, pt_maker_fn>& global_registry();
95
};
96

97
#define BOTAN_REGISTER_PERF_TEST(name, Perf_Class)                \
98
   const Botan_CLI::PerfTest::Registration reg_perf_##Perf_Class( \
99
      name, []() -> std::unique_ptr<Botan_CLI::PerfTest> { return std::make_unique<Perf_Class>(); })
100

101
}  // namespace Botan_CLI
102

103
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc