added iterations/sec counter (when verbose)

This commit is contained in:
Bob Polis 2020-11-21 14:05:47 +01:00
parent c448c4a416
commit 1d60582afd

View File

@ -12,8 +12,10 @@
#include <stdexcept>
#include <vector>
#include <memory>
#include <thread>
#include <getopt.h>
#include <sqlite3.h>
#include <sc/integer_locale.hpp>
#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';