# Math: calculating bytes per second

**URL:** <https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006>\
**Category:** Uncategorized\
**Created:** [August 6, 2002, 6:10am UTC](https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006 "2002-08-06T06:10:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![upuaut](https://avatars.discourse-cdn.com/v4/letter/u/9fc348/32.png) [@upuaut](https://forum.kirupa.com/u/upuaut)\
**Post date:** [August 6, 2002, 6:10am UTC](https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006/1 "2002-08-06T06:10:41Z")

</div>

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.

totalK=getBytesTotal();  
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

estimatedTimeRemaining=(loadedK-oldLoadedK)/(time-oldTime)\*remainingK;

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2002, 7:17am UTC](https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006/2 "2002-08-06T07:17:12Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2002, 7:43am UTC](https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006/3 "2002-08-06T07:43:07Z")

</div>

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

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

thanks supra

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2002, 7:20pm UTC](https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006/4 "2002-08-06T19:20:38Z")

</div>

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.

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2002, 4:57am UTC](https://forum.kirupa.com/t/math-calculating-bytes-per-second/1006/5 "2002-08-07T04:57:37Z")

</div>

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

Grrr…

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.
