Math: calculating bytes per second

This is really bugging me. I should not be having a problem doing this sort of thing. Hopefuly someone here will know what I’m doing wrong.

I’ve got a loop set up wherein I
A) set oldTime equal to time
B) set oldLoadedK equal to loadedK
C) set time equal to getTimer(). Divided by 1000 to get seconds
D) set loadedK equal to getBytesLoaded();
E) set remainingK equal to totalK minus loadedK

now… I should be able to figure out estimated time remaining.

I’m thinking it’s


but for some reason this doesn’t seem to work. Can anyone tell me if it’s my math, or should I be looking for syntax errors?

math looks fine to me.

if you use the whole of what’s loaded rather than just the last loops worth of information, you’ll get a more accurate estimate

sTime is the time when the download commenced.

estTime = (getTimer() - sTime) * (totalBytes/loadedBytes);

ok good… at least I’m not just dumb. :slight_smile:

I’ll check for syntax errors and then impliment the change you suggested.

thanks supra

oops, just noticed something.

that code i posted will return the estimated total time. to get the remaining time, you’d have to subtract the time which has passed.

elapsedTime = getTimer() - sTime;
remainingTime = elapsedTime * (totalBytes/loadedBytes) - elapsedTime;

ahh… the whole thing still isn’t working right.


of course I’m not doing it exactly like that so I’ve a feeling it’s something else…

I’ll let you know how I come along. Thanks for the reitteration.