I have made a program that goes like this, the goal is to estimate the remaining time of a function (it is running a bunch of solveChase[] functions with different parameters which can be seen in the best answer of this question):



If in another cell I put:

Print[Dynamic@Round[100 (precision count + count2)/(precision max1 max2),.01], "%" ];

(which shows the percentage of all the process, from 0 to 100%)

That value will change, but because of SomeFunction[var] (a NDSolve result which its running time depends on i and j) not in a linear way.

It has different rates of change in some parts, so it has a velocity which is not constant and can be calculated.

This is a example(sorry for bad quality):

example of not linear remaining time on some calculations

My guess is to insert another variable t, which depends on time, and then do something with it, but I don't know how to do it.

Any help will be appreciated.


2 Answers 2

n = 10; {a, b} = {0, 0};
somefun[i_, j_] := (Pause[i/40]; Pause[j/80]; i + j)
estimatedTime[i_, j_] := i/40 + j/80
totalTime = Sum[estimatedTime[i, j], {i, n}, {j, n}];

timeUpToij[h_, k_] := Sum[estimatedTime[i, j], {i, h}, {j, n}] - 
                      Sum[estimatedTime[h, j], {j, k + 1, n}]

Dynamic@ProgressIndicator[timeUpToij[a, b]/totalTime]
Table[({a, b} = {i, j}; somefun[i, j]), {i, n}, {j, n}]

Mathematica graphics

  • $\begingroup$ If I run this code, I get a ProgressIndicator which runs on a "random" way, which is similar to the example. I'm actually trying to calculate the calculating speed at any time t $\endgroup$
    – Arcotick
    Jan 29, 2014 at 13:05
  • $\begingroup$ @Arcotick You need to fill in estimatedTime[] with YOUR estimated time $\endgroup$ Jan 29, 2014 at 13:07
  • $\begingroup$ By the way, how did you take a photo of the output cell? $\endgroup$
    – Arcotick
    Jan 29, 2014 at 13:07
  • $\begingroup$ But what if I don't know the estimated time? it can any number bigger than 0. Do I need to calculate the timing of that function and then multiply it by the steps? $\endgroup$
    – Arcotick
    Jan 29, 2014 at 13:10
  • $\begingroup$ @Arcotick You can't make a linear progress indicator if you can't estimate the time, sorry $\endgroup$ Jan 29, 2014 at 13:22

Unless you know the run-time for each invocation of your function in advance it is not possible to display progress (in terms of time).

You can estimate the time remaining using (1-f)(t-t0)/f where f is the fraction of invocations so far, t is the current time and t0 is the start time.

As a simple example, first set-up an approximate remaining-time estimate display:

Dynamic[(iMax/count - 1) (AbsoluteTime[] - t0)]

Then run the "calculation":

iMax = 100;
count = 0;
t0 = AbsoluteTime[];
Table[count++;Pause[RandomReal[{0.1, 0.3}]];i, {i, iMax}]

Replace Pause[...];i with your calculation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.