From 1d60582afd86ee3aafe047516ced6d54c847bbd3 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sat, 21 Nov 2020 14:05:47 +0100 Subject: [PATCH] added iterations/sec counter (when verbose) --- src/main.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 34385ba..80608ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,8 +12,10 @@ #include #include #include +#include #include #include +#include #include "robinsonizer_mode.hpp" #include "engine.hpp" @@ -137,8 +139,27 @@ int main(int argc, const char * argv[]) { if (start.size() == 0) start = "This sentence contains"; if (maxiter == 0) maxiter = 10; engine robinsonizer {start, std::move(numerals), maxiter, mode, verbose}; - robinsonizer.run(); - std::cout << robinsonizer << '\n'; + if (verbose) { + std::locale loc {std::locale {}, new sc::integer_locale}; + std::cerr.imbue(loc); + std::cout.imbue(loc); + + std::thread worker {[&robinsonizer](){robinsonizer.run();}}; + + unsigned long long cur_iter {robinsonizer.total_iterations()}; + unsigned long long prev_iter {0}; + + while (!robinsonizer.found()) { // show progress info + prev_iter = cur_iter; + std::this_thread::sleep_for(std::chrono::seconds{1}); + cur_iter = robinsonizer.total_iterations(); + std::cerr << '\r' << cur_iter - prev_iter << " iterations per second, " << cur_iter << " total "; + } + worker.join(); + } else { + robinsonizer.run(); + } + std::cout << '\n' << robinsonizer << '\n'; } catch (const std::exception& ex) { std::cerr << "autogram: " << ex.what() << '\n';