Search code examples
c#algorithm

Calculate Time Remaining


What's a good algorithm for determining the remaining time for something to complete? I know how many total lines there are, and how many have completed already, how should I estimate the time remaining?


Solution

  • Why not?

    (linesProcessed / TimeTaken) (timetaken / linesProcessed) * LinesLeft = TimeLeft

    TimeLeft will then be expressed in whatever unit of time timeTaken is.

    Edit:

    Thanks for the comment you're right this should be:

    (TimeTaken / linesProcessed) * linesLeft = timeLeft

    so we have

    (10 / 100) * 200 = 20 Seconds now 10 seconds go past
    (20 / 100) * 200 = 40 Seconds left now 10 more seconds and we process 100 more lines
    (30 / 200) * 100 = 15 Seconds and now we all see why the copy file dialog jumps from 3 hours to 30 minutes :-)