I sometimes run lengthy computations, overnight or even over 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 itd 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.

Clear["Global`*"];

SetAttributes[RemainingTime, HoldAll];

RemainingTime[content_, ticker_, min_, max_, period_] :=

Block[{T0 = AbsoluteTime[], toTimE, timE},

ticker = min;

Monitor[content,

Refresh[

timE = AbsoluteTime[] - T0;

toTimE = (max - min) timE/(ticker - min + (max - min) 10^-6);

Panel@Grid[

{{"current value ", ProgressIndicator[ticker, {min, max}],

ticker},

{"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 non-uniform in time computations, like finding prime numbers, we can obviously see some trouble:

RemainingTime[

primes = {};

Do[If[PrimeQ[2^i - 1], AppendTo[primes, i]], {i, 1000, 5000}];

primes

, i, 1000, 5000, .1]

Let me know any suggestions or post any improvements or variations. For instance, how do we account for non-uniform in time computations?