diff options
author | Jack Lloyd <[email protected]> | 2016-02-17 22:59:14 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-02-20 12:33:11 -0500 |
commit | 99f2c04783b0a33d606531b73b1b3d0d1f52daa3 (patch) | |
tree | 7dea16b31742da548d2ea46f960149e887b295d3 /src/cli/speed.cpp | |
parent | b244336a8ee17e2aadd4c239c2467e1510f3dbc5 (diff) |
Add tests and timings for inverse_mod
Diffstat (limited to 'src/cli/speed.cpp')
-rw-r--r-- | src/cli/speed.cpp | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index b643bd605..45a0b4717 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -190,13 +190,21 @@ std::string Timer::result_string_ops(const Timer& timer) const double events_per_second = timer.events() / timer.seconds(); - oss << timer.get_name() << " " - << static_cast<uint64_t>(events_per_second) - << ' ' << timer.doing() << "/sec; " - << std::setprecision(2) << std::fixed - << timer.ms_per_event() << " ms/op" - << " (" << timer.events() << " " << (timer.events() == 1 ? "op" : "ops") - << " in " << timer.milliseconds() << " ms)\n"; + oss << timer.get_name() << " "; + + if(timer.events() == 0) + { + oss << "no events\n"; + } + else + { + oss << static_cast<uint64_t>(events_per_second) + << ' ' << timer.doing() << "/sec; " + << std::setprecision(2) << std::fixed + << timer.ms_per_event() << " ms/op" + << " (" << timer.events() << " " << (timer.events() == 1 ? "op" : "ops") + << " in " << timer.milliseconds() << " ms)\n"; + } return oss.str(); } @@ -360,6 +368,10 @@ class Speed final : public Command { bench_random_prime(msec); } + else if(algo == "inverse_mod") + { + bench_inverse_mod(msec); + } #endif else if(algo == "RNG") { @@ -601,6 +613,25 @@ class Speed final : public Command } #if defined(BOTAN_HAS_NUMBERTHEORY) + + void bench_inverse_mod(const std::chrono::milliseconds runtime) + { + const Botan::BigInt p = random_prime(rng(), 1024); + + Timer invmod_timer("inverse_mod"); + + while(invmod_timer.under(runtime)) + { + const Botan::BigInt x(rng(), 1023); + + const Botan::BigInt x_inv1 = invmod_timer.run([&]{ + return Botan::inverse_mod(x, p); + }); + } + + output() << Timer::result_string_ops(invmod_timer); + } + void bench_random_prime(const std::chrono::milliseconds runtime) { const size_t coprime = 65537; // simulates RSA key gen |