From 5bedae43e66002aefadce0b6d43bf6791d5156ca Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 20 Aug 2015 19:49:31 +0200 Subject: Refactor ./botan speed * Add random_prime benchmark * Add is_prime benchmark * Respect runtime in benchmark_transform(). This sets default runtime from 2s to 0.5s per configuration --- src/lib/misc/benchmark/benchmark.cpp | 18 +++++++++--------- src/lib/utils/exceptn.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src/lib') diff --git a/src/lib/misc/benchmark/benchmark.cpp b/src/lib/misc/benchmark/benchmark.cpp index 90d8b1aca..152b45d37 100644 --- a/src/lib/misc/benchmark/benchmark.cpp +++ b/src/lib/misc/benchmark/benchmark.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -153,19 +154,18 @@ algorithm_benchmark(const std::string& name, size_t buf_size) { //Algorithm_Factory& af = global_state().algorithm_factory(); - const auto providers = get_all_providers_of(name); + const auto provider_names = get_all_providers_of(name); + if (provider_names.empty()) + throw No_Provider_Found(name); std::map all_results; // provider -> ops/sec - if(!providers.empty()) - { - const std::chrono::nanoseconds ns_per_provider = milliseconds / providers.size(); + const std::chrono::nanoseconds ns_per_provider = milliseconds / provider_names.size(); - for(auto provider : providers) - { - auto results = time_algorithm_ops(name, provider, rng, ns_per_provider, buf_size); - all_results[provider] = find_first_in(results, { "", "update", "encrypt" }); - } + for(auto provider : provider_names) + { + auto results = time_algorithm_ops(name, provider, rng, ns_per_provider, buf_size); + all_results[provider] = find_first_in(results, { "", "update", "encrypt" }); } return all_results; diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h index 7e16a5dec..eef1b4d43 100644 --- a/src/lib/utils/exceptn.h +++ b/src/lib/utils/exceptn.h @@ -112,6 +112,16 @@ struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error {} }; +/** +* No_Provider_Found Exception +*/ +struct BOTAN_DLL No_Provider_Found : public Exception + { + No_Provider_Found(const std::string& name) : + Exception("Could not find any provider for algorithm named \"" + name + "\"") + {} + }; + /** * Invalid_Algorithm_Name Exception */ -- cgit v1.2.3