|
You might have seen the download dialog of windows, which informs about the download progress as well as the estimated time left to complete the download. How would you calculate that time? I would do it like this:
During the download progress, the full size of the file downloaded is known of course. Download is done package by package. Package is a small part of the full file. So, when the package arrives, we can find out the size of the package. Of course getting the package takes some amount of time, as the download is done through internet network and depends on the speed and other factors. When starting getting the next package you should somehow save the time when this particular operation started, and when the package is already on our side of the wire, you should check how long have you been waiting for the package to arrive. In other words, using the size of package and the time you can calculate the current download speed (which, in fact, changes during the download). For example: package size = 4kb, time used = 1 second. So, the speed is 4 kb per second, or 1 kb per 0.25 seconds. So, the only thing you must calculate is how much kb-s you have left to download. That means the estimated time will be 0.25 seconds multiplied by the size in kilobytes of the download resource.
If I would have to create a download manager, this information would be a little useful for me.
And, as an answer to the title, I must say, if given the whole amount of operation, and it can be divided approximately in the same size of sub-operations, this way we can calculate the estimated time left for any operation to complete.
|