Its not as hard as it sounds anyone can do this by throwing some javascript. Most of the speed test sites that are available, downloads a predefined file (a jpg or something with known size) and then uses javascript to find the time elapsed and then calculate the result.
In one of the popular site I saw something like this:
<html>
<script language="JavaScript">
function RightNow()
{
time = new Date();
return time.getTime();
}
function CalculateSpeed(timeStart)
{
timeEnd = RightNow();
timeElapsed = (timeEnd - timeStart)/1000 - 0.15;
kbytes = 1024/timeElapsed;
bits = kbytes * 1024 * 8;
document.forms[0].bps.value = bits;
//document.forms[0].submit();
}
</script>
<BODY >
<div>Bandwidth test in progress, please wait...<br><br></div>
<script language="JavaScript">
<!--
timeStart = RightNow();
//-->
</script>
<IMG SRC="http://something.com/images/1024.1.jpg?
a=10.54561000+1168998701" WIDTH="30" HEIGHT="30"
ONLOAD="CalculateSpeed(timeStart);" style="z-index: 1">
<FORM action="" method="post">
bits:<input type="text" name="bps" value="">
</FORM>
</BODY>
</html>
Note: There should be a mechanism to make sure the URL of the dowloadable image is dynamically generated and is different each time to avoid caching.