# # old_revision [c18c4c9d2fbcdaaf08fb448837b778e6f30968a6] # # patch "sha1.cc" # from [5b5488b7d19a740f70bae5d82c709c9549c5f38d] # to [043d71e9c34c20fb8b0a6e901a1cfb779a26656b] # ============================================================ --- sha1.cc 5b5488b7d19a740f70bae5d82c709c9549c5f38d +++ sha1.cc 043d71e9c34c20fb8b0a6e901a1cfb779a26656b @@ -14,6 +14,29 @@ #include #include +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,22) + #include + #include + + // Choose a timer implementation + #if defined(BOTAN_HAS_TIMER_POSIX) + #include + typedef Botan::POSIX_Timer benchmark_timer_class; + #elif defined(BOTAN_HAS_TIMER_UNIX) + #include + typedef Botan::Unix_Timer benchmark_timer_class; + #elif defined(BOTAN_HAS_TIMER_WIN32) + #include + typedef Botan::Win32_Timer benchmark_timer_class; + #elif + /* This uses ANSI clock and gives somewhat bogus results + due to the poor resolution + */ + typedef Botan::Timer benchmark_timer_class; + #endif + +#endif + #include "sanity.hh" #include "ui.hh" #include "platform.hh" @@ -28,6 +51,25 @@ CMD_HIDDEN(benchmark_sha1, "benchmark_sh options::opts::none) { P(F("Benchmarking botan's SHA-1 core")); + +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,22) + benchmark_timer_class timer; + Botan::AutoSeeded_RNG rng; + Botan::Algorithm_Factory& af = + Botan::global_state().algorithm_factory(); + + const int milliseconds = 5000; + + std::map results = + Botan::algorithm_benchmark("SHA-1", milliseconds, timer, rng, af); + + for(std::map::const_iterator i = results.begin(); + i != results.end(); ++i) + { + P(F("SHA-1 provider '%s': %s MiB/s") % i->first % i->second); + } + +#else int mebibytes = 100; string test_str(mebibytes << 20, 'a'); data test_data(test_str); @@ -37,6 +79,7 @@ CMD_HIDDEN(benchmark_sha1, "benchmark_sh double end = cpu_now(); double mebibytes_per_sec = mebibytes / (end - start); P(F("%s MiB/s") % mebibytes_per_sec); +#endif }