added iterations/sec counter (when verbose)
This commit is contained in:
parent
c448c4a416
commit
1d60582afd
23
src/main.cpp
23
src/main.cpp
@ -12,8 +12,10 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
#include <sc/integer_locale.hpp>
|
||||||
#include "robinsonizer_mode.hpp"
|
#include "robinsonizer_mode.hpp"
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
|
||||||
@ -137,8 +139,27 @@ int main(int argc, const char * argv[]) {
|
|||||||
if (start.size() == 0) start = "This sentence contains";
|
if (start.size() == 0) start = "This sentence contains";
|
||||||
if (maxiter == 0) maxiter = 10;
|
if (maxiter == 0) maxiter = 10;
|
||||||
engine robinsonizer {start, std::move(numerals), maxiter, mode, verbose};
|
engine robinsonizer {start, std::move(numerals), maxiter, mode, verbose};
|
||||||
|
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();
|
robinsonizer.run();
|
||||||
std::cout << robinsonizer << '\n';
|
}
|
||||||
|
std::cout << '\n' << robinsonizer << '\n';
|
||||||
|
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
std::cerr << "autogram: " << ex.what() << '\n';
|
std::cerr << "autogram: " << ex.what() << '\n';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user