|
| 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 { |
| 22 | + public: |
| 23 | + virtual ~PerfConfig() = default; |
| 24 | + |
| 25 | + virtual std::chrono::milliseconds runtime() const = 0; |
| 26 | + |
| 27 | + //virtual std::vector<std::string> providers() const = 0; |
| 28 | + |
| 29 | + virtual const std::vector<size_t>& buffer_sizes() const = 0; |
| 30 | + |
| 31 | + virtual std::ostream& error_output() const = 0; |
| 32 | + |
| 33 | + virtual Botan::RandomNumberGenerator& rng() const = 0; |
| 34 | + |
| 35 | + virtual void record_result(const Botan::Timer& timer) const = 0; |
| 36 | + |
| 37 | + virtual std::unique_ptr<Botan::Timer> make_timer(const std::string& alg, |
| 38 | + uint64_t event_mult = 1, |
| 39 | + const std::string& what = "", |
| 40 | + const std::string& provider = "", |
| 41 | + size_t buf_size = 0) const = 0; |
| 42 | +}; |
| 43 | + |
| 44 | +class PerfTest { |
| 45 | + public: |
| 46 | + virtual ~PerfTest() = default; |
| 47 | + |
| 48 | + // Returns nullptr if unknown / not available |
| 49 | + static std::unique_ptr<PerfTest> get(const std::string& alg); |
| 50 | + |
| 51 | + virtual void go(const PerfConfig& config) = 0; |
| 52 | + |
| 53 | + typedef std::function<std::unique_ptr<PerfTest>()> pt_maker_fn; |
| 54 | + |
| 55 | + class Registration final { |
| 56 | + public: |
| 57 | + Registration(const std::string& name, const std::function<std::unique_ptr<PerfTest>()>& maker_fn); |
| 58 | + }; |
| 59 | + |
| 60 | + private: |
| 61 | + static std::map<std::string, pt_maker_fn>& global_registry(); |
| 62 | +}; |
| 63 | + |
| 64 | +#define BOTAN_REGISTER_PERF_TEST(name, Perf_Class) \ |
| 65 | + const Botan_CLI::PerfTest::Registration reg_perf_##Perf_Class( \ |
| 66 | + name, []() -> std::unique_ptr<Botan_CLI::PerfTest> { return std::make_unique<Perf_Class>(); }) |
| 67 | + |
| 68 | +} // namespace Botan_CLI |
| 69 | + |
| 70 | +#endif |
0 commit comments