limit the progressBar update rate to 5 per second. This speeds up loading of small bin files.

This commit is contained in:
phdussud 2020-12-24 14:35:05 -08:00
parent 6fefebd02c
commit 11baca9337
2 changed files with 12 additions and 5 deletions

View File

@ -17,6 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "time.h"
#include "progressBar.hpp" #include "progressBar.hpp"
#include "display.hpp" #include "display.hpp"
@ -24,9 +25,15 @@ ProgressBar::ProgressBar(std::string mess, int maxValue, int progressLen):
_mess(mess), _maxValue(maxValue), _progressLen(progressLen) _mess(mess), _maxValue(maxValue), _progressLen(progressLen)
{ {
} }
static time_t last_time;
void ProgressBar::display(int value) void ProgressBar::display(int value, char force)
{ {
clock_t this_time = clock();
if (!force && ((((float)(this_time - last_time))/CLOCKS_PER_SEC) < 0.2))
{
return;
}
last_time = this_time;
float percent = ((float)value * 100.0f)/(float)_maxValue; float percent = ((float)value * 100.0f)/(float)_maxValue;
float nbEq = (percent * (float) _progressLen)/100.0f; float nbEq = (percent * (float) _progressLen)/100.0f;
@ -41,13 +48,13 @@ void ProgressBar::display(int value)
} }
void ProgressBar::done() void ProgressBar::done()
{ {
display(_maxValue); display(_maxValue, true);
//fprintf(stderr, "\nDone\n"); //fprintf(stderr, "\nDone\n");
printSuccess("\nDone"); printSuccess("\nDone");
} }
void ProgressBar::fail() void ProgressBar::fail()
{ {
display(_maxValue); display(_maxValue, true);
//fprintf(stderr, "\nDone\n"); //fprintf(stderr, "\nDone\n");
printError("\nFail"); printError("\nFail");
} }

View File

@ -23,7 +23,7 @@
class ProgressBar { class ProgressBar {
public: public:
ProgressBar(std::string mess, int maxValue, int progressLen); ProgressBar(std::string mess, int maxValue, int progressLen);
void display(int value); void display(int value, char force = 0);
void done(); void done();
void fail(); void fail();
private: private: