123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home

Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)

Forums

   Computer Science / IT

   Electronics

   Electrical

   Mechanical

   Chemical

   Civil

   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs

Sitemap

About-Us

Terms of use

Displaying  Source Code(s)  
 

 
Speed: Measuring Code Speed

--------------------------------------------------------------------------------

Description : Measuring speed to the millisecond was considered impossible with ASP. People built COM components that wrapped up API calls! So we called a COM component that called an API and then we distorted the measurement with overhead. Scripting has a few tricks up its sleeves yet as Richard demonstrates with the nifty Library implemented in Jscript. We will use it to time retrieving and displaying identical data three different ways: traditional loop and movenext one getrows call one getstring call This method is great for testing optimizations to 1 script but does not show how the script will run when many users are simultaneously executing it. Tools like the Stress Tester at: http://homer.rte.microsoft.com are great for simulating and recording measurements for multi-user performance.

Here we retrieve data using a traditional Loop (/learn/dbtable.asp):

<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>

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG