I've written a simple upload/download speed test using jQuery and ajax to test clients' ul/dl speed with our own server. I know that javascript tests of this nature aren't known for being greatly accurate, but my results in comparison to Speedof.me and Speedtest.net are way off. As a comparison, I did a few tests with no other internet activities active:
Speedof.me - 26.5 down 5.7 up
Speedtest.net - 26.5 down 5.3 up
OpenSpeedTest.com - 12.0 down 3.5 up
My Tool - 7.7 down 4.7 up
It's been suggested that the difference could be entirely server-related, but could that really account for so large a discrepancy? I don't think our server is that slow... We use Coldfusion, so that adds a slight twist in that CF has functions that get run with every request (onRequestStart(), onRequestEnd()), including ajax requests. But, I'm suppressing those two functions for my ajax calls. My basic code is below. Using ajax, I'm downloading and uploading a text file named lorem.txt that's approximately 10MB in size.
var ajaxTime= new Date().getTime();
var fileSize = <cfoutput>#nFileSizeMegaBits#</cfoutput>;
var request = jQuery.ajax({
url: "/myPath/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;
//this is where I populate the page with the test result
jQuery('#dlSpeedSpan').html(nDLSpeedMbps + "Mbps");
//Do upload timer test
//note that this new ajax call is done inside of the download ajax call's success function; so that both tests won't run at the same time
var ajaxTimeUpload = new Date().getTime();
var formData = new FormData();
formData.append("xxtestTextxx", request.responseText);//i.e., all 10MB of the text from Lorem.txt
var requestUpload = jQuery.ajax({
url: '/myPath/blank.cfm',
type: 'POST',
data: formData,
processData: false,
contentType: false,
mimeType: 'multipart/form-data',
cache: false,
success: function(data) {
var totalTimeUpload = new Date().getTime()-ajaxTimeUpload;
var mbpsUpload = fileSize/(totalTimeUpload/1000);
mbpsUpload = mbpsUpload.toFixed(2);
nULSpeedMbps = mbpsUpload;
//populate page with test result
jQuery('#ulSpeedSpan').html(nULSpeedMbps + "Mbps");
});
requestUpload.fail(function(xhr, status) {
jQuery('#ulSpeedSpan').html( "Ajax Request failed: " + status );
});
}
});
request.fail(function( jqXHR, textStatus ) {
jQuery('#dlSpeedSpan').html( "Ajax Request failed: " + textStatus );
});
});