9 bool Progress_Bar::print_progress() noexcept
12 bool actually_printed =
false;
18 const auto now = std::chrono::steady_clock::now();
19 std::chrono::duration<double> duration_since_last = now - last_print_time;
20 if (done == total || duration_since_last.count() >= gap)
22 actually_printed =
true;
23 std::chrono::duration<double> duration_since_start = now - start;
24 last_print_time = now;
26 const double duration = duration_since_start.count();
29 std::ostringstream line;
31 line << std::fixed << std::setprecision(1);
32 const int width = int(std::to_string(total).size());
33 line << std::setw(width) << done <<
" / " << total <<
' ';
34 line << std::setw(5) << 100.0f*float(done)/float(total) <<
'%';
42 double n = double(done) / duration;
56 line << std::fixed << std::setprecision(1) << n << unit <<
"/s";
61 const double time_left = double(total - done) * duration / double(done);
62 line <<
"; " << time_left <<
"s left";
66 logger.
log(line.str());
80 return actually_printed;
95 start(
std::chrono::steady_clock::now()),
96 last_print_time(start)
105 return print_progress();
virtual void log(beman::cstring_view message) noexcept
Progress_Bar(int64_t total, Logger &logger)
bool print(int64_t current)