0

Can anyone please let me know how I can properly calculate the download speed like Ookla speed tester.

I have tried to calculate it with the following approach but still not getting the correct result.

I am downloading a file from CDN and calculate the time it takes to download the complete file. Then divide it. for e.g.:

  1. open a connection with URL
  2. var starting time in milliseconds.
  3. download the file
  4. var endTime in milliseconds
  5. Speed = (downloadSize in bits) / ((endTime-Startime)/1000)
Harun Diluka Heshan
  • 1,155
  • 2
  • 18
  • 30
Tin Kills
  • 11
  • 1
  • What result did you expect to get? – GalAbra Jun 03 '19 at 09:57
  • What result did you get and how is it different with your expected result? – willy1994 Jun 03 '19 at 09:59
  • when i run the test from ookla i get aroung 10 - 15 Mbps downloading speed. while when i run my code i get 1 - 3 Mbps speed . – Tin Kills Jun 03 '19 at 09:59
  • 2
    @Tin Kills seems like there is a ~8 ratio there, are you sure you're not missing a bytes to bits conversion in your calculations ? – BJRINT Jun 03 '19 at 10:01
  • @BJRINT no the conversion is correct . is there any better way to do this. i am currently doing this with javascript . or do i need to condiser any other factors in calcutation – Tin Kills Jun 03 '19 at 10:06
  • Whilst I am not the man to help you with this problem **you should post your code** – Scott Anderson Jun 03 '19 at 10:08
  • @Tin Kills Assuming you have some control over the backend you could handle this with a [stream](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) and the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File) by breaking the downloaded data into small chunks and getting the instant rate of bytes/ms (which is what i assume Ookla does). This will be pretty accurate, but if it is really worth the effort for your use case that I cannot answer ... – BJRINT Jun 03 '19 at 14:21

0 Answers0