From 97d1e025dcf1f62b7b6849df4ef5f13ca1b57ecd Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 10 Apr 2011 18:01:58 +0200 Subject: [PATCH] parallel: Small fix for ETA. --- doc/release_new_version | 2 ++ src/parallel | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/release_new_version b/doc/release_new_version index a948d272..eb95eee1 100644 --- a/doc/release_new_version +++ b/doc/release_new_version @@ -165,6 +165,8 @@ New in this release: ? Part of Debian? ? Part of Ubuntu? +* Thanks to Ævar Arnfjörð Bjarmason for reading my code. + * GNU Parallel was presented at: - LUGA, Augsburg, 2011-03-26, http://www.luga.de/Aktionen/LIT-2011/Programm - OSAA.dk, Aarhus, 2011-04-12 diff --git a/src/parallel b/src/parallel index 5e43108e..a76df493 100755 --- a/src/parallel +++ b/src/parallel @@ -1008,13 +1008,22 @@ sub progress { my $left = $total - $completed; my $pctcomplete = $completed / $total; my $timepassed = (time - $Private::first_completed); - my $avgtime = $timepassed / $completed; + my $avgtime = $timepassed / $completed; $Private::smoothed_avg_time ||= $avgtime; - # Smooth the eta so it does not jump wildly + # Smooth the eta so it does not jump wildly $Private::smoothed_avg_time = (1 - $pctcomplete) * $Private::smoothed_avg_time + $pctcomplete * $avgtime; - my $this_eta = $left * $Private::smoothed_avg_time; - $eta = sprintf("ETA: %ds %dleft %.2favg ", $this_eta, $left, $avgtime); + my $this_eta; + $Private::last_time ||= $timepassed; + if($timepassed != $Private::last_time + or not defined $Private::last_eta) { + $Private::last_time = $timepassed; + $this_eta = $left * $Private::smoothed_avg_time; + $Private::last_eta = $this_eta; + } else { + $this_eta = $Private::last_eta; + } + $eta = sprintf("ETA: %ds %dleft %.2favg ", $this_eta, $left, $avgtime); } } @@ -1635,9 +1644,6 @@ sub my_size { } } -# Guvf vf n grfg gb frr vs bguref ner ernqvat zl pbqr. Cyrnfr rznvy -# pbbxvr@gnatr.qx jura lbh ernq guvf - sub my_dump { # Returns: # ascii expression of object if Data::Dump(er) is installed