Estimated remaining time: monitoring lengthy computations

Posted by & filed under Community, Wolfram.

I just posted on Wolfram Community. For comments – go to the original post. An here is what it is about.

I sometimes run lengthy computations, overnight or even a few days. We have built in Monitor function to track the progress of a variable. But I often find it useful to estimate how much time is left till a computation is done. It is easy to estimate, but it’d be nice to have it monitored automatically. Like many OS do, for example, for files transfer.

Below I give a prototype of a function that does it. The idea is very simple and assumes that computations are approximately uniform in time. A typical usage case would be some image processing of large directory of images. We compute the rate based on variable (e.g. number of images) progress and time passed. The rate allows estimating remaining time. Here is the legend for its arguments:

  • content – the computation to track
  • ticker – the variable to track
  • min – minimum (starting) value of ticker
  • max – maximum (ending) value of ticker
  • period – periodicity to check the status of computation with

“period” is needed because monitoring in principle slows down the original computation. To reduce the slow-down check for the computation status with longer (than single iteration) time intervals.

 SetAttributes[RemainingTime, HoldAll];
 RemainingTime[content_, ticker_, min_, max_, period_] :=
  Block[{T0 = AbsoluteTime[], toTimE, timE},
   ticker = min;
     timE = AbsoluteTime[] - T0;
     toTimE = (max - min) timE/(ticker - min + (max - min) 10^-6);
      {{"current value  ", ProgressIndicator[ticker, {min, max}], 
       {"remaining time ", 
        ProgressIndicator[toTimE - timE, {0, toTimE}], 
        Round[toTimE - timE]}},
      Alignment -> Left],
    UpdateInterval -> period, TrackedSymbols -> {}]

Now let see how the function works. For uniform in time computations it works fine:

RemainingTime[Do[Pause[0.01], {i, 1, 500}], i, 1, 500, .1]

For comments and suggestions visit the original post.