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 <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++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue