From b067a61fe565161c2915cfddf316cbb45849f461 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 30 Jul 2010 16:20:46 +0000 Subject: Add a new option for benchmarking --buf-size which specifies the size of the buffer (in KiB) to process. --- checks/bench.cpp | 9 +++++---- checks/bench.h | 6 ++++-- checks/check.cpp | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/checks/bench.cpp b/checks/bench.cpp index 5ee50d89d..8d35ac1c4 100644 --- a/checks/bench.cpp +++ b/checks/bench.cpp @@ -162,14 +162,15 @@ void report_results(const std::string& algo, bool bench_algo(const std::string& algo, Botan::RandomNumberGenerator& rng, - double seconds) + double seconds, + u32bit buf_size) { Botan::Algorithm_Factory& af = Botan::global_state().algorithm_factory(); u32bit milliseconds = static_cast(seconds * 1000); std::map speeds = - algorithm_benchmark(algo, milliseconds, rng, af); + algorithm_benchmark(algo, af, rng, milliseconds, buf_size); if(speeds.empty()) // maybe a cipher mode, then? { @@ -243,8 +244,8 @@ bool bench_algo(const std::string& algo, } void benchmark(Botan::RandomNumberGenerator& rng, - double seconds) + double seconds, u32bit buf_size) { for(u32bit i = 0; algos[i] != ""; ++i) - bench_algo(algos[i], rng, seconds); + bench_algo(algos[i], rng, seconds, buf_size); } diff --git a/checks/bench.h b/checks/bench.h index 835db0101..b423a2215 100644 --- a/checks/bench.h +++ b/checks/bench.h @@ -6,11 +6,13 @@ #include void benchmark(Botan::RandomNumberGenerator& rng, - double seconds); + double seconds, + u32bit buf_size); bool bench_algo(const std::string& algo_name, Botan::RandomNumberGenerator& rng, - double seconds); + double seconds, + u32bit buf_size); void bench_pk(Botan::RandomNumberGenerator&, const std::string&, double seconds); diff --git a/checks/check.cpp b/checks/check.cpp index 74348402a..d2a05ab35 100644 --- a/checks/check.cpp +++ b/checks/check.cpp @@ -103,7 +103,8 @@ int main(int argc, char* argv[]) try { OptionParser opts("help|test|validate|dyn-load=|" - "benchmark|bench-type=|bench-algo=|seconds="); + "benchmark|bench-type=|bench-algo=|" + "seconds=|buf-size="); opts.parse(argv); test_types(); // do this always @@ -149,6 +150,8 @@ int main(int argc, char* argv[]) { double seconds = 5; + u32bit buf_size = 16; + if(opts.is_set("seconds")) { seconds = std::atof(opts.value("seconds").c_str()); @@ -159,9 +162,19 @@ int main(int argc, char* argv[]) } } + if(opts.is_set("buf-size")) + { + buf_size = std::atoi(opts.value("buf-size").c_str()); + if(buf_size == 0 || buf_size > 8192) + { + std::cout << "Invalid argument to --buf-size\n"; + return 2; + } + } + if(opts.is_set("benchmark")) { - benchmark(rng, seconds); + benchmark(rng, seconds, buf_size); } else if(opts.is_set("bench-algo")) { @@ -171,7 +184,7 @@ int main(int argc, char* argv[]) for(u32bit j = 0; j != algs.size(); j++) { const std::string alg = algs[j]; - if(!bench_algo(alg, rng, seconds)) // maybe it's a PK algorithm + if(!bench_algo(alg, rng, seconds, buf_size)) bench_pk(rng, alg, seconds); } } -- cgit v1.2.3