开发者

Calculate estimated time in a program

I'm making a program and I want to give to the user information about the estimated times every 1000 elements processed. I'm calculating time in this way:

  • C = elements processed so far
  • MAX = Max elements to process
  • Tp = time elapsed
  • Te = time estimated

In theory, the relation between elements processed and elapsed time is equal to the relation between the rest of the elements and the rest of tim开发者_如何学运维e, so my formula is:

(C/Tp) = (MAX - C)/(Te - Tp)

So I need to solve Te by doing:

(Te - Tp) = (MAX - C)Tp/C

And finally:

Te = (MAX - C)Tp/C + Tp

I think that resolution is correct but clearly, operation doesn't tend to 0 as C and Tp grows, so I'm sure that I'm doing a stupid mistake but I couldn't find.

Some ideas please?


I think your initial equation is slightly off, rather than what you have it should be

(C/Tp) = (MAX - C)/Te

since we're estimating the time required to process each item, and this should be constant and equal in the past and the future. This will give you a final equation

Te = (MAX - C)*(Tp/C)

which tends to zero as expected.

(This is assuming that Te is the estimated time left, not estimated total time)


I think it's fine. You're probably thinking about "time remaining", which in your case would be Tr = Te - Tp. That one does tend to 0.

Start: C = 0, results in divide by zero. Makes sense, you have no speed indication so there's no estimate.

End: C = MAX, MAX-C=0, so Te=Tp. Makes sense, estimate is now equal to elapsed time.

Halfway, C=MAX/2, MAX-C = C, so Te=C*Tp/C + Tp, or about twice the current amount passed. Makes sense.

One quarter, C = MAX/4, MAX-C=3*C, so Te=3*C*Tp / C + Tp, or Te = 4*Tp. Makes sense, again.


You shouldn't take the entire time that elapsed.

You should just take the average of the last 4-5 chunks of 1000 objects. Because that will give you a more accurate idea of the current speed of calculation.

t1,t2,t3,t4 = last 4 calculations

thisIteration = timePassedSinceLastCheck/1000 //Avg time per object
Te = (Max-C)*Avg(t1,t2,t3,t4,thisIteration)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜