如何获得asp页面的载入时间
<!— how can i time the execution speed of my asp pages to the millisecond? —>
doing this is easy with a simple server-side javascript function:
<script language=jscript runat=server>
function gettime()
{
var d = new date();
return d.gettime();
}
</script>
the gettime() method of the date object in jscript returns the number of millisecond since jan 1st, 1970. therefore all you have to do it take a reading immediately before and after the process you are wanting to time. the following is an example, given that the above code it in gettime.asp:
dim starttime, endtime
starttime = gettime()
do some stuff here
endtime = gettime()
response.write "the process took: " & _
cstr(endtime-starttimes) & "ms to execute"
if you want to see your process time in a better format, use the formatmilliseconds function (created for the above timing script by www.learnasp.com):
function formatmilliseconds(intmilliseconds)
{
var elapsedsecs = 0
ar elapsedmins = 0
elapsedsecs=math.floor(intmilliseconds/1000);
intmilliseconds=intmilliseconds%1000;
elapsedmins=math.floor(elapsedsecs/60)
elapsedsecs=elapsedsecs%60;
elapsedpretty=elapsedmins + " minute";
if(elapsedmins!=1)
elapsedpretty=elapsedpretty+"s";
elapsedpretty = elapsedpretty+" " + elapsedsecs+" second";
if(elapsedsecs!=1)
elapsedpretty=elapsedpretty+"s";
elapsedpretty = elapsedpretty+ " " +
intmilliseconds+" millisecond";
if(intmilliseconds!=1)
elapsedpretty=elapsedpretty+"s";
return elapsedpretty;
}
