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

randombit / botan / 11376677396

17 Oct 2024 12:10AM UTC coverage: 91.125% (+0.006%) from 91.119%
11376677396

push

github

web-flow
Merge pull request #4378 from randombit/jack/speed-cleanup

Cleanups after refactoring of speed cli

90992 of 99854 relevant lines covered (91.13%)

9363281.76 hits per line

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

95.0
/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 <botan/internal/timer.h>
13
#include <chrono>
14
#include <functional>
15
#include <iosfwd>
16
#include <map>
17
#include <string>
18

19
namespace Botan_CLI {
20

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

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

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

44
      std::chrono::milliseconds runtime() const { return m_runtime; }
129✔
45

46
      std::ostream& error_output() const { return m_error_output; }
×
47

48
      Botan::RandomNumberGenerator& rng() const { return m_rng; }
10,135✔
49

50
      void record_result(const Botan::Timer& timer) const { m_record_result(timer); }
753✔
51

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

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

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

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

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

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

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

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

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

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

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

100
}  // namespace Botan_CLI
101

102
#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