Performance: Update progress bar only when changed
This commit is contained in:
parent
e038ab224d
commit
bf55c2d0a9
1 changed files with 7 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -41,9 +42,13 @@
|
|||
#define BAR_WIDTH 50
|
||||
|
||||
void print_progress(int current, int total) {
|
||||
static int last = INT_MAX;
|
||||
float fraction = (float)current / total;
|
||||
int filled = (int)(fraction * BAR_WIDTH);
|
||||
|
||||
if (filled == last)
|
||||
return; /* Avoid unnecessary io/flushes */
|
||||
|
||||
printf("\r[");
|
||||
for (int i = 0; i < BAR_WIDTH; i++) {
|
||||
if (i < filled)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue