66#define PROGRESS_H
77
88#include < iostream>
9+ #include < iomanip>
910#include < string>
1011#include < chrono>
1112#include < sstream>
@@ -46,10 +47,23 @@ class ProgressBar {
4647 const int r_min = (int )(rest_time / 1000.0 ) / 60 ;
4748 const int r_sec = (int )(rest_time / 1000.0 ) % 60 ;
4849
50+ std::string it_text = " " ;
4951 const int steps_per_sec = (int )(1000.0 / time_msec_per_step);
50- std::ostringstream oss;
51- oss << steps_per_sec;
52- const std::string it_text = steps_per_sec < 1000 ? oss.str () : " 1000+" ;
52+ if (steps_per_sec > 0 ) {
53+ std::ostringstream oss;
54+ if (steps_per_sec < 1000 ) {
55+ oss << steps_per_sec;
56+ } else {
57+ oss << " 1000+" ;
58+ }
59+ oss << " it/s" ;
60+ it_text = oss.str ();
61+ } else {
62+ std::ostringstream oss;
63+ oss << std::setprecision (2 );
64+ oss << time_msec_per_step / 1000.0 << " s/it" ;
65+ it_text = oss.str ();
66+ }
5367
5468 const int tick = (int )(m_width * m_step / m_total);
5569 std::string pbar = std::string (tick, ' =' );
@@ -63,7 +77,7 @@ class ProgressBar {
6377 if (!m_description.empty ()) {
6478 Print (" %s " , m_description.c_str ());
6579 }
66- Print (" [%3d%%]|%s| %d/%d [%02d:%02d<%02d:%02d, %sit/ s]" , (int )percent, pbar.c_str (), m_step, m_total, n_min,
80+ Print (" [%3d%%]|%s| %d/%d [%02d:%02d<%02d:%02d, %s]" , (int )percent, pbar.c_str (), m_step, m_total, n_min,
6781 n_sec, r_min, r_sec, it_text.c_str ());
6882 }
6983
0 commit comments