Skip to content

Commit

Permalink
Improve progress line printing when scanning extrafiles.
Browse files Browse the repository at this point in the history
Old version calculated new/oldfraction for every byte of the file
which leads to poor performance:

par2 v test.par2 *:

old   : 1m38sec
old -q: 1m5sec
new   : 1m5sec
  • Loading branch information
jkansanen committed Jul 26, 2017
1 parent 71679b0 commit c246258
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/par2repairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,6 @@ bool Par2Repairer::ScanDataFile(DiskFile *diskfile, // [in]
// Which block do we expect to find first
const VerificationHashEntry *nextentry = 0;

u64 progress = 0;

// How far will we scan the file (1 byte at a time)
// before skipping ahead looking for the next block
u64 scandistance = min(skipleaway<<1, blocksize);
Expand All @@ -1528,20 +1526,30 @@ bool Par2Repairer::ScanDataFile(DiskFile *diskfile, // [in]

bool progressline = false;

u64 oldoffset = 0;
u64 printprogress = 0;

// Whilst we have not reached the end of the file
while (filechecksummer.Offset() < diskfile->FileSize())
{
if (noiselevel > CommandLine::nlQuiet)
{
// Update a progress indicator
u32 oldfraction = (u32)(1000 * progress / diskfile->FileSize());
u32 newfraction = (u32)(1000 * (progress = filechecksummer.Offset()) / diskfile->FileSize());
if (oldfraction != newfraction)
// Update progress indicator
printprogress += filechecksummer.Offset() - oldoffset;
if (printprogress == blocksize || filechecksummer.ShortBlock())
{
cout << "Scanning: \"" << shortname << "\": " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;
u32 oldfraction = (u32)(1000 * (filechecksummer.Offset() - printprogress) / diskfile->FileSize());
u32 newfraction = (u32)(1000 * filechecksummer.Offset() / diskfile->FileSize());
printprogress = 0;

if (oldfraction != newfraction)
{
cout << "Scanning: \"" << shortname << "\": " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;

progressline = true;
progressline = true;
}
}
oldoffset = filechecksummer.Offset();
}

// If we fail to find a match, it might be because it was a duplicate of a block
Expand Down

3 comments on commit c246258

@Safihre
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

@Safihre
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkansanen @BlackIkeEagle Could we get 0.7.4 with this in it?
We always use verbose output so our users could use this speedup! πŸŽ‰πŸŽˆ

@Safihre
Copy link
Contributor

@Safihre Safihre commented on c246258 Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping πŸ˜‰

Please sign in to comment.