0

Let's say I download a file that is 3500 bytes in 2401 milliseconds. What is the calculation to work out Internet speed?

I ask because I'm developing a piece of software that does just this to make a guess at the users current internet speed. My problem is I don't how to use these 2 numbers to calculate the Mbps.

Here's what I've got so far. Not sure if I'm on the right track but I'm getting the wrong result.

  1. I convert the bytes to bits by multiplying the bytes by 8
  2. Divide the bits by the number of seconds it took to transfer the file to get bits per second
  3. Divide by 1,000,000 to get the Mbps

Mbps = ((fileBytes * 8) / durationInSeconds) / 1000000

If I put my numbers into this function I get a completely different result:

((3500) * 8) / 2.401) / 1000000
(28000 / 2.401) / 1000000
11661.80758017492711 / 1000000
= 0.01166180758017

The result 0.01166180758017 is not correct as my Internet speed is ~4Mbps. Where am I going wrong?

1 Answers1

2

Your math is right, the download speed turns out to be abysmal because of other issues.

Try a (significantly) bigger file. (I mean a lot bigger: 100s of MBytes.) Otherwise, the actual download time is swamped by the time it takes to connect to the host and exchange all the other messages (e.g. SSL/TLS handshake if you run over HTTPS), plus the time the host itself takes to respond.

  • Ah, this might be a problem. The constraints of the test I'm performing mean the download can take no longer than a second. Is it completely impossible to make a close estimate to the users possible download speed? – BugHunterUK Jan 11 '18 at 20:25
  • Also to add, the result of the duration of the download is the actual time it took to download minus the handshake etc. So the 2041 is the actual time it took to download the file. – BugHunterUK Jan 11 '18 at 20:26
  • @BugHunterUK I don't know. At 4Mbit/sec, the actual download of your 3500-byte file would take 0.007 sec. Where was the rest (2.041 sec - 0.007 sec = 2.034 sec) spent? I don't know. You will need to figure it out and eliminate those factors. In my answer I pointed to a few usual culprits, but I cannot comment on what is the problem in your particular setup. Have you tried to run the network monitor software (e.g. Wireshark) and see the packets? Anyway we are leaving the realm of mathematics and going into software/hardware: maybe this site is not the best place to discuss those issues? –  Jan 11 '18 at 20:32
  • Very good point. And agreed. I'll chew this over tonight. Thanks for your input it has been useful. Oh also I am not looking for the users ISP speed but their current internet speed at that moment in time. – BugHunterUK Jan 11 '18 at 20:36
  • Over two seconds to download a tiny file (3500 bytes will fit in two Ethernet packets!) is way too long a delay to be accounted for by handshakes and server latency unless the server is seriously unwell. @BugHunterUK, are you sure you haven't inadvertently counted microseconds instead of milliseconds, or something like that? Also, "current internet speed" in practice is a very hard concept to pin down -- so hard that it is arguable whether it exists at all. – hmakholm left over Monica Jan 11 '18 at 20:53
  • @HenningMakholm I was thinking that possibly it also took the time to store the file on the disk, scan it via Anti-Virus, which itself had to connect to its cloud during the scan as many of them do... Who knows... The OP needs to sort it out. –  Jan 11 '18 at 20:58