3

To measure client download speed, I'm using an ajax get call to a text file of known size, and using the javascript date prototype's getTime() function to measure how long it took. I chose this for its simplicity, but for some reason, this is returning vastly slower numbers than I get with speedtest.net. Is there a more accurate way to do this?

var ajaxTime = new Date().getTime();
var request = jQuery.ajax({
                    url: "/eventdata/(default)/system_diagnostics/lorem.txt?s=" + ajaxTime,
                    type: "GET",
                    success: function(result) {//success
                        var totalTime = new Date().getTime()-ajaxTime;
                        var mbps = fileSize/(totalTime/1000);
                        mbps = mbps.toFixed(2);
                        nDLSpeedMbps = mbps;

Where fileSize is the size of the text file in megabits.

The only thing I can think of is that the browser is occupied doing other things that use up bandwidth, but I don't know what. There is an upload test (another ajax call) on the same page, but that doesn't fire off until further down in the success function, after the download ajax call is finished and nDLSpeedMbps has been calculated.

Cmaso
  • 1,095
  • 1
  • 10
  • 23
  • 1
    d/l speed is affected by not only the client's download speed/bandwidth, but also the network speeds/bandwidth of the server that you are downloading from. – Kevin B Jan 06 '15 at 18:30
  • 1
    This one was really accurate for me: http://stackoverflow.com/questions/5529718/how-to-detect-internet-speed-in-javascript . But the problem is probably the server bandwidth – juvian Jan 06 '15 at 18:41
  • The JavaScript user timing API http://www.html5rocks.com/en/tutorials/webperformance/usertiming/ should improve the accuracy of your duration measurements - and thus the accuracy of the results. – pwdst Jan 06 '15 at 20:22
  • I find the script you posted just fine. – Viktor Joras May 14 '19 at 11:49

0 Answers0