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

randombit / botan / 12130573488

03 Dec 2024 12:33AM UTC coverage: 91.264% (+0.006%) from 91.258%
12130573488

push

github

web-flow
Merge pull request #4456 from randombit/jack/split-timer

Split up Timer logic

93394 of 102334 relevant lines covered (91.26%)

11563440.65 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 <string>
17

18
#include "timer.h"
19

20
namespace Botan_CLI {
21

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

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

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

45
      std::chrono::milliseconds runtime() const { return m_runtime; }
139✔
46

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

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

51
      void record_result(const Timer& timer) const { m_record_result(timer); }
759✔
52

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

61
   private:
62
      std::function<void(const 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 {
46✔
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