diff options
Diffstat (limited to 'doc/examples/bench.cpp')
-rw-r--r-- | doc/examples/bench.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/doc/examples/bench.cpp b/doc/examples/bench.cpp index 884bc2ecc..87b3a57f7 100644 --- a/doc/examples/bench.cpp +++ b/doc/examples/bench.cpp @@ -67,29 +67,42 @@ const std::string algos[] = { "", }; -int main() + +void benchmark_algo(const std::string& algo, + RandomNumberGenerator& rng) { - LibraryInitializer init; + const u32bit milliseconds = 1000; + Algorithm_Factory& af = global_state().algorithm_factory(); std::map<std::string, double> speeds = algorithm_benchmark(algo, af, rng, milliseconds, 16*1024); - Algorithm_Factory& af = global_state().algorithm_factory(); + std::cout << algo << ":"; - for(u32bit i = 0; algos[i] != ""; ++i) + for(std::map<std::string, double>::const_iterator i = speeds.begin(); + i != speeds.end(); ++i) { - std::string algo = algos[i]; + std::cout << " " << i->second << " [" << i->first << "]"; + } + std::cout << "\n"; + } - std::map<std::string, double> speeds = - algorithm_benchmark(algos[i], milliseconds, rng, af); +} - std::cout << algo << ":"; +int main(int argc, char* argv[]) + { + LibraryInitializer init; + + AutoSeeded_RNG rng; - for(std::map<std::string, double>::const_iterator i = speeds.begin(); - i != speeds.end(); ++i) - { - std::cout << " " << i->second << " [" << i->first << "]"; - } - std::cout << "\n"; + if(argc == 1) // no args, benchmark everything + { + for(size_t i = 0; algos[i] != ""; ++i) + benchmark_algo(algos[i], rng); + } + else + { + for(size_t i = 1; argv[i]; ++i) + benchmark_algo(argv[i], rng); } } |