Determine the Connection Speed of your client

How many times have you written the perfect application, you spend hours getting it right, only to be told it is running slow.  You have performed all the Performance Tuning, and you still get the users saying it is running slowly.

One issue is with the clients connection speed, they may be over GPRS or a dial up connection.  You have no control over the users connections speeds, so to help this out why not check their connection speed and if it is running slow then provide a warning message.

The following code will work out your clients connection speed.  The only issue with such code is you have to wait until it is completed before you know the speed.  To over come this I use an iFrame on the web page, so to speed of connection is worked out in a separate window to the main application.  Meaning the client can continue to work while the calculation is taking place.

What and how you tell the client, is really up to you, one way is to display a JavaScript alert message giving them a warning, but be careful not to display this information too many times as they may get a little annoyed being told they have a slow connection speed when they already know they have,

int numKB = 512;

DateTime start;

DateTime end;

TimeSpan duration;

int length = 0;

string checklen = "\n";

private double CalculateSpeed()



start = DateTime.Now;

length = checklen.Length;

for (int i = 0; i < numKB; i++)


hfSpeedTest.Value += "".PadRight(1024 – length, "/*\\*"[0]) + "\n";



end = DateTime.Now;

duration = (end – start);

double timediff = numKB / duration.TotalSeconds;

double speed = System.Math.Round(timediff, 3);hfSpeedTest.Value =

""; return speed;