Performance: Update progress bar only when changed

This commit is contained in:
Imbus 2026-02-15 03:10:54 +01:00
parent e038ab224d
commit bf55c2d0a9

View file

@ -3,6 +3,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <limits.h>
#include <signal.h> #include <signal.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -41,8 +42,12 @@
#define BAR_WIDTH 50 #define BAR_WIDTH 50
void print_progress(int current, int total) { void print_progress(int current, int total) {
float fraction = (float)current / total; static int last = INT_MAX;
int filled = (int)(fraction * BAR_WIDTH); float fraction = (float)current / total;
int filled = (int)(fraction * BAR_WIDTH);
if (filled == last)
return; /* Avoid unnecessary io/flushes */
printf("\r["); printf("\r[");
for (int i = 0; i < BAR_WIDTH; i++) { for (int i = 0; i < BAR_WIDTH; i++) {