diff --git a/fdupes.c b/fdupes.c index 76a7136..0ce4df7 100644 --- a/fdupes.c +++ b/fdupes.c @@ -57,6 +57,10 @@ #include "xdgbase.h" #endif +// Only print progress every Nth loop iteration +// Should be a (multiple of 4) + 1 +#define PROGRESS_DIVIDER 65 + char *program_name; long long minsize = -1; @@ -302,8 +306,12 @@ int grokdir(char *dir, file_t **filelistp, struct stat *logfile_status) if (strcmp(dirinfo->d_name, ".") && strcmp(dirinfo->d_name, "..")) { if (!ISFLAG(flags, F_HIDEPROGRESS)) { - fprintf(stderr, "\rBuilding file list %c ", indicator[progress]); - progress = (progress + 1) % 4; + // Only print progress every n-th file to reduce (terminal) CPU use + // (multiple of 4 + 1 so the indicator still alternate properly) + if ( progress % PROGRESS_DIVIDER == 0 ) { + fprintf(stderr, "\rBuilding file list %c ", indicator[progress % 4]); + } + progress++; } newfile = (file_t*) malloc(sizeof(file_t)); @@ -1855,8 +1863,11 @@ int main(int argc, char **argv) { curfile = curfile->next; if (!ISFLAG(flags, F_HIDEPROGRESS)) { - fprintf(stderr, "\rProgress [%d/%d] %d%% ", progress, filecount, - (int)((float) progress / (float) filecount * 100.0)); + // Only print progress every 65th file to reduce (terminal) CPU used to display progress + if ( progress % PROGRESS_DIVIDER == 0 ) { + fprintf(stderr, "\rProgress [%d/%d] %d%% ", progress, filecount, + (int)((float) progress / (float) filecount * 100.0)); + } progress++; } }