Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate estimated time in a program

Tags:

c++

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 time, 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?

like image 693
Killrazor Avatar asked Feb 21 '26 10:02

Killrazor


2 Answers

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)

like image 79
You Avatar answered Feb 23 '26 23:02

You


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.

like image 28
dascandy Avatar answered Feb 23 '26 23:02

dascandy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!