Thread: estimating time remaining

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    2

    Lightbulb estimating time remaining

    I am working on a c++ program, It basically copys file into another file. I current have the program outputting how many mb it has done and the pecentage of the operation (i.e 5mb out of 50mb 10% complete)

    i would also like to add an estimated remaining time and elapsed time if possible. Therefore the output would like like:-

    5MB out of 50MB 10% Complete Estimated time remaining 2:21 mins. Total time elapsed 1 min

    Any thoughts off how i can do this, please let me know

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    The sneaky way: just use a random number generator to make up a time.

  3. #3
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    set a timer for 10 seconds.
    after 10 seconds take the percent done. lets say its 10%

    you have 9 * 10 seconds left.
    divide by 60 to get minutes
    % 60 to get seconds

    now you just gota find out how to use timers

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    PercentDone is a real number (0.0 -> 1.0) telling how much of the file is complete (0.0 = 0%, 1.0 = 100%).
    SecondsTaken contains how many seconds have passed so far.
    Code:
    long int GetTimeLeft(double PercentDone, long int SecondsTaken)
    {
       //Prevent division by 0
       if(PercentDone == 0.0) return 0;
    
       //Calculate the time remaining
       return (long int)(((double)SecondsTaken / PercentDone) - (double)SecondsTaken + 0.99999);
    }
    EDIT: The last 0.99999 is for rounding perfection (skip it if you like, who cares for a +/- second )
    Last edited by Magos; 05-24-2003 at 06:02 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Is there any function that returns the length of a file?
    Example:
    Code:
    int main(){
       
       ifstream inFile("File.txt");
    
       cout << "The size of the file is " << inFile.size();
    
       return 0;
    }
    This function(if exists) could solve all the problem...
    Nothing more to tell about me...
    Happy day =)

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    long int GetFileLength(const char* FileName)
    {
       ifstream ReadFile;
       long int Size;
    
       ReadFile.open(FileName, ios::in | ios::nocreate | ios::binary);
       if(ReadFile.fail())
       {
          return -1;
       }
    
       ReadFile.seekg(0, ios::end);
       Size = ReadFile.tellg();
    
       ReadFile.close();
       return Size;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Time remaining is never going to be accurate, only an estimate. Consider, you start the copy and nothing else is running, part way through, some heavy resource using program starts or resumes running, now your copy could start running much slower, timings will be out.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Determine the closest departure time
    By Kyeong in forum C Programming
    Replies: 9
    Last Post: 10-07-2008, 08:06 PM
  3. Scheduling
    By Jules in forum Tech Board
    Replies: 4
    Last Post: 01-18-2004, 01:47 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM