How to check upload and download speed

3.9k views Asked by At

I am trying to write a code for checking the upload and download speed of my ISP by using USB Dongle. The server in the dongle is Lighttpd.

My current plan for download is to write a shell script that downloads a file from a server(the file should be big enough) and kill the process in 2 seconds.I can then get the file size.I repeat the process n times(10 here) , and take the average.Statistically i believe moving average is the best value.Please help.

ALSO,

My plan for upload is taking a big file(20 MB) and upload it using shell script(php also can be used), and use it to measure speed. I am not sure how to measure the upload speed here.I need bridge the communication gap, where the device hardware has the value and i need to get the proper value to be displayed to the user.Need help here.

The Code for upload is as follows.(its a javascript file) NOTE: var params is around 350 KiB

var uploadhttp;
var url = "http://www.example.com";
var params = 
"RANDOM CHARACTER SET. This lone character file should be large enough";




function getHTTPObject() {

    if(!uploadhttp && typeof XMLHttpRequest != "undefined") 
    {
      try
        {     
        if(BrowserType=="MSIE")
            uploadhttp=new XDomainRequest(); 
        else
            uploadhttp = new XMLHttpRequest();          
        }
        catch(e)
        {
            alert(e);
        }
/*      if(!uploadhttp){
            //alert("uploadhttp object creation failed");
            }
            else{
            //alert("uploadhttp object created successfully");
            }
 */ }

}

function handler() {//Call a function when the state changes.
    if(uploadhttp.readyState == 4 && uploadhttp.status == 200) {
        //alert(uploadhttp.responseText);
    }
}

function getMethod() {
    getHTTPObject();
    /* if(!uploadhttp)
        //alert("failed to create object"); */

    if(uploadhttp)
    {
        uploadhttp.open("GET", url, true);
        uploadhttp.onreadystatechange = handler;
        uploadhttp.send(null);
    }
}

function postMethod() {
    try
    {
    getHTTPObject();
    //if(!uploadhttp)
        //alert("failed to create object");
    if(uploadhttp)
    {
        uploadhttp.open("POST", url, true);//,"jio","rancore");
    }

    //Send the proper header infomation along with the request
    //uploadhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    uploadhttp.onreadystatechange = handler;
    if(BrowserType=="MSIE")
    {
        uploadhttp.send(params);
    }
    else
    {
        var iLen = bufferedData.length;
        uploadhttp.send(bufferedData);
    }
    }
    catch(e)
    {
       alert(e);
    }
}
1

There are 1 answers

5
Igor Chubin On

You can download a file using wget and measure downloading time using `time. So, the you can write something like:

time wget http://....

wget can measure time also, but I would prefer time here, because it reports entire amount of time used for downloading.

To test upload speed you can use curl:

time curl -i -F name=test -F [email protected] http://example.org/upload