Skip to content

Commit 7a84b76

Browse files
committed
refactor: reorganize progress line formatting
1 parent 1de34c0 commit 7a84b76

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

util.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,16 @@ void pretty_progress(int step, int steps, float time) {
269269
}
270270
}
271271
progress += "|";
272-
printf(time > 1.0f ? "\r%s %i/%i - %.2fs/it\033[K" : "\r%s %i/%i - %.2fit/s\033[K",
273-
progress.c_str(), step, steps,
274-
time > 1.0f || time == 0 ? time : (1.0f / time));
275-
fflush(stdout); // for linux
276-
if (step == steps) {
277-
printf("\n");
272+
273+
const char* lf = (step == steps ? "\n" : "");
274+
const char* unit = "s/it";
275+
float speed = time;
276+
if (speed < 1.0f && speed > 0.f) {
277+
speed = 1.0f / speed;
278+
unit = "it/s";
278279
}
280+
printf("\r%s %i/%i - %.2f%s\033[K%s", progress.c_str(), step, steps, speed, unit, lf);
281+
fflush(stdout); // for linux
279282
}
280283

281284
std::string ltrim(const std::string& s) {

0 commit comments

Comments
 (0)