作者在 2006-06-14 01:10:00 发布以下内容
我们在访问某些网站,特别是虚拟主机服务商的网站经常会看到一个速度测试的按钮,可以测试用户本地连接到某台服务器的连接速度,这样的程序其实也可以用asp轻松实现,具体如下:
<%
Const DataSize=100 '测试数据量,单位K,值越大,测试越精确,但速度越慢,推荐值100K左右
Response.Buffer=false
oneK=String(1024,"A")
TotalData=""
for i=1 to DataSize
TotalData=TotalData & oneK
next
Response.write "<html><head><title>速度测试程序</title></head><body>"
Response.write "<form name=form1><span align=center><input type=text id=Info size=30 value=""速度测试中,请稍候.."" ReadOnly><input type=button name=reload value=""重新测试"" onClick=""location.reload();""></span></form>"
Response.write "<script language=javascript>function formatNumber(nu) { num=Math.floor(nu*100);num=num/100;return num;}</script>"
Response.write "<script language=javascript>var beginTime=new Date();</script><!--"
Response.write TotalData
Response.write "--><script language=javascript>var endTime=new Date();allTime=endTime.getTime()-beginTime.getTime();allTime=allTime / 1000;speed=formatNumber(" & DataSize & "/ allTime);document.getElementById(""Info"").value='连接到XX机房的速度:'+speed+'K/S';</script>"
Response.write "</body></html>"
%>
<%
Const DataSize=100 '测试数据量,单位K,值越大,测试越精确,但速度越慢,推荐值100K左右
Response.Buffer=false
oneK=String(1024,"A")
TotalData=""
for i=1 to DataSize
TotalData=TotalData & oneK
next
Response.write "<html><head><title>速度测试程序</title></head><body>"
Response.write "<form name=form1><span align=center><input type=text id=Info size=30 value=""速度测试中,请稍候.."" ReadOnly><input type=button name=reload value=""重新测试"" onClick=""location.reload();""></span></form>"
Response.write "<script language=javascript>function formatNumber(nu) { num=Math.floor(nu*100);num=num/100;return num;}</script>"
Response.write "<script language=javascript>var beginTime=new Date();</script><!--"
Response.write TotalData
Response.write "--><script language=javascript>var endTime=new Date();allTime=endTime.getTime()-beginTime.getTime();allTime=allTime / 1000;speed=formatNumber(" & DataSize & "/ allTime);document.getElementById(""Info"").value='连接到XX机房的速度:'+speed+'K/S';</script>"
Response.write "</body></html>"
%>