Measuring Code Speed in ASP/VB
<html><head> <TITLE>timedbtable.asp</TITLE> </head> <body bgcolor="#FFFFFF"> <!--#include file="lib_timethis.asp"--> <% Set HttpObj = Server.CreateObject("AspHTTP.Conn") HttpObj.Url = "http://www.learnasp.com/learn/test/dbtable.asp" timeThen = milliDif() strResult = HttpObj.GetURL timeNow = milliDif() Set HTTPobj = Nothing elapsed=timeNow-timeThen msg=" Process time in ms: " & elapsed & "<BR> & elapsedpretty(elapsed) bodytag="<body bgcolor=""#FFFFFF"">" STRresult=Replace(STRResult,bodytag,bodytag & msg) Response.Write STRresult %> </body></html> Here we retrieve data by fetching all the data into an Array In one "gulp" (/learn/dbtablegetrows.asp): <html><head> <TITLE>timedbtablegetrows.asp</TITLE> </head> <body bgcolor="#FFFFFF"> <!--#include file="lib_timethis.asp"--> <% Set HttpObj = Server.CreateObject("AspHTTP.Conn") HttpObj.Url = "http://www.learnasp.com/learn/test/dbtablegetrows.asp" timeThen = milliDif() strResult = HttpObj.GetURL timeNow = milliDif() Set HTTPobj = Nothing elapsed=timeNow-timeThen msg=" Process time in ms: " & elapsed & "<BR> & elapsedpretty(elapsed) bodytag="<body bgcolor=""#FFFFFF"">" STRresult=Replace(STRResult,bodytag,bodytag & msg) Response.Write STRresult %> </body></html> Here we retrieve data by asking the backend To combine the data into a custom String And Not even bring fields And rows, just produce 1 String (/learn/dbtablegetstring.asp): <html><head> <TITLE>timedbtablegetstring.asp</TITLE> </head> <body bgcolor="#FFFFFF"> <!--#include file="lib_timethis.asp"--> <% Set HttpObj = Server.CreateObject("AspHTTP.Conn") HttpObj.Url = "http://www.learnasp.com/learn/test/dbtablegetstring.asp" timeThen = milliDif() strResult = HttpObj.GetURL timeNow = milliDif() Set HTTPobj = Nothing elapsed=timeNow-timeThen msg=" Process time in ms: " & elapsed & "<BR> & elapsedpretty(elapsed) bodytag="<body bgcolor=""#FFFFFF"">" STRresult=Replace(STRResult,bodytag,bodytag & msg) Response.Write STRresult %> </body></html> The library that accomplishes this: <SCRIPT LANGUAGE=JScript RUNAT=Server> Function y2k(number) { return (number < 1000) ? number + 1900 : number; } Function milliDif() { var d = New Date(); return d.getTime() } Function elapsedpretty(parm1) { var elapsedsecs = 0 var elapsedmins = 0 elapsedsecs=Math.floor(parm1/1000) parm1=parm1%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+ " "+parm1+" millisecond" If(parm1!=1) elapsedpretty=elapsedpretty+"s" return elapsedpretty; } </script>