views:

47

answers:

1

It's common to see messages like "Installation will take 10 min aprox." , etc in desktop applications. So, I wonder how can I calculate an approximate of how much time a certain process will take. Off course I won't install anything but I want to update some internal data and depending on the user usage this might take some time.

Is this possible in a iPhone app? How Cocoa guys do this, would it be the same way in iPhone apps?

Thanks in advance.

UPDATE: I want to rewrite/edit some files on disk, most of the time these files are not the same size so I cannot use timers for the first iteration and calculate the rest from that. Is there any API that helps on calculating this?

+1  A: 

If you have some list of things to process, each "thing" - usually better to measure a group of 10 or so "things" - is a unit of work. Your goal is to see how long it takes to process a single group and report the estimated time to completion.

One way is to create an NSDate at the start of each group and a new one at the end (the top and bottom of your for loop) for each group. Multiply the difference in seconds by however many groups you have left (minus the one you just processed) and that should be a reasonable estimate of the time remaining.

Of course this gets more complicated if one "thing" takes a lot longer to process than another "thing" - the above approach assumes all things take the same amount of time. In this case, however, you may need to keep track of an average window (across the last n "things" or groups thereof).

A more detailed response would require more details about your model and what work you're performing.

Joshua Nozzi
I just updated my question, I hope its clearer now ;)
nacho4d
Measure the time it takes for each file and use that file's size to determine the data written per second. Apply this rate to the total remaining files' sizes.
Joshua Nozzi
I see, very simple. But, is this accurate enough? I had the impression it would be something more complicated and maybe had to access some hardware to know the clock speed, memory, or something but this sounds like a work-arround. Doesn't it?
nacho4d
Are you giving your user progress feedback or tracking subatomic particles in an accelerator? How precise must you be? Just try it and see if it works well enough for your needs.
Joshua Nozzi