Tutorials to .com

Tutorials to .com » Asp » Optimization » asp performance test report (switch) (b)

asp performance test report (switch) (b)

Print View , by: iSee ,Total views: 12 ,Word Count: 1694 ,Date: Fri, 17 Apr 2009 Time: 11:34 PM

On the server to generate dynamic content using ASP, one of the most important reason, we choose the first test is to determine the dynamic content sent to the response stream using the best methods. There are two basic options (as well as some of their changes): the use of tags embedded in ASP, use Response.Write statements.

To test these different approaches, we have created a simple asp page, the page to the definition of some variables and then insert them into the form. Although this page is very simple, and there is no practical use, but it is enough for us to isolate and test the various issues.

2.1 the use of tags embedded ASP

The first test is to use the embedded ASP tags <% = x%>, in which x is a variable. This is the most convenient way to use, and it allows some HTML pages easier to read and maintain.
Dim FirstName
Dim LastName
Dim MiddleInitial
Dim Address
Dim City
Dim State
Dim PhoneNumber
Dim FaxNumber
Dim EMail
Dim BirthDate

FirstName = "John"
MiddleInitial = "Q"
LastName = "Public"
Address = "100 Main Street"
City = "New York"
State = "NY"
PhoneNumber = "1-212-555-1234"
FaxNumber = "1-212-555-1234"
EMail = "john@public.com"
BirthDate = "1/1/1950"

<TITLE> Response Test </ TITLE>
</ HEAD>
<H1> Response Test </ H1>
<Tr> <td> <b> First Name: </ b> </ td> <td> <% = FirstName%> </ td> </ tr>
<Tr> <td> <b> Middle Initial: </ b> </ td> <td> <% = MiddleInitial%> </ td> </ tr>
<Tr> <td> <b> Last Name: </ b> </ td> <td> <% = LastName%> </ td> </ tr>
<Tr> <td> <b> Address: </ b> </ td> <td> <% = Address%> </ td> </ tr>
<Tr> <td> <b> City: </ b> </ td> <td> <% = City%> </ td> </ tr>
<Tr> <td> <b> State: </ b> </ td> <td> <% = State%> </ td> </ tr>
<Tr> <td> <b> Phone Number: </ b> </ td> <td> <% = PhoneNumber%> </ td> </ tr>
<Tr> <td> <b> Fax Number: </ b> </ td> <td> <% = FaxNumber%> </ td> </ tr>
<Tr> <td> <b> EMail: </ b> </ td> <td> <% = EMail%> </ td> </ tr>
<Tr> <td> <b> Birth Date: </ b> </ td> <td> <% = BirthDate%> </ td> </ tr>
</ BODY>
</ HTML>
/ app1/response1.asp complete code

The best record = 8.28 ms / page

2.2 use Response.Write output HTML code for each line

Pointed out that a lot of good literature, should avoid the use of tags embedded in front, because it leads to a group called the "context switch" operation. The operation took place in Web server code to deal with changes in the type of when (from a purely HTML sent to the script processing, or in turn), which will take some time to switch. Many programmers to understand this point, their first reaction is to each line of HTML code Response.Write function is used to output:
Response.Write ( "<html>")
Response.Write ( "<head>")
Response.Write ( "<title> Response Test </ title>")
Response.Write ( "</ head>")
Response.Write ( "<body>")
Response.Write ( "<h1> Response Test </ h1>")
Response.Write ( "<table>")
Response.Write ( "<tr> <td> <b> First Name: </ b> </ td> <td>" & FirstName & "</ td> </ tr>")
Response.Write ( "<tr> <td> <b> Middle Initial: </ b> </ td> <td>" & MiddleInitial & "</ td> </ tr>")
/ app1/response2.asp clips

The best record = 8.28 ms / page
Response time = 8.08 ms / page
Difference = -0.20 ms (decrease 2.4%)

And the embedded version of tag, we have seen a very small performance improvement, it is surprising. This may be because the page a lot more function call. This approach, however there is a greater drawback, as the HTML code embedded into a function, the script code becomes very long and not easy to read and maintain.

2.3 the use of package functions

Response.Write line in the text does not end with CRLF (Carriage Return - Line Feed, carriage return line feed), which is to use the method above, where the most disappointing. Although in the server-side HTML code to a good format, but in your browser still only see a long line of code. But disappointment is not only a problem, people soon discovered there was no CRLF automatically added to the Response.WriteLn function. A very natural reaction is to create the package Response.Write function, in the back of each line with CRLF:
writeCR ( "<tr> <td> <b> First Name: </ b> </ td> <td>" & FirstName & "</ td> </ tr>")
SUB writeCR (str)
Response.Write (str & vbCRLF)
/ app1/response4.asp clips

The best record = 8.08 ms / page
Response time = 10.11 ms / page
Difference = +2.03 ms (an increase of 25.1%)

The result is a significant decline in performance. Of course, this is mainly because this method allows doubling the number of function calls, it is very obvious impact on performance. Should at all costs to avoid such usage, CRLF at the end of each line resulted in more than two bytes, which is two bytes for the browser page is of no use. In most cases, the browser-side code HTML format only facilitates the appearance of your competitors to read and understand the design of the page.

2.4 more than the combined Response.Write

If you do not consider the last time the test function of the package, the next logical step should be separated from all the strings from the Response.Write statements into one statement, thus reducing the number of function calls to improve the operating efficiency of the code.
Response.Write ( "<html>" & _
"<Head>" & _
"<Title> Response Test </ title>" & _
"</ Head>" & _
"<Body>" & _
"<H1> Response Test </ h1>" & _
"<Table>" & _
"<Tr> <td> <b> First Name: </ b> </ td> <td>" & FirstName & "</ td> </ tr>" & _
"<Tr> <td> <b> Birth Date: </ b> </ td> <td>" & BirthDate & "</ td> </ tr>" & _
"</ Table>" & _
"</ Body>" & _
"</ Html>")
/ app1/response3.asp clips

The best record = 8.08 ms / page
Response time = 7.05 ms / page
Difference = -1.03 ms (decrease 12.7%)

This is the best way so far.

2.5 combine multiple Response.Write, and at the end of each line to increase CRLF

It was also very concerned about their HTML code in the browser side is beautiful, so we each line in the HTML code to add a carriage return at the end, using a constant vbCRLF other test cases with the same code.
Response.Write ( "<html>" & vbCRLF & _
"<Head>" & vbCRLF & _
"<Title> Response Test </ title>" & vbCRLF & _
"</ Head>" & vbCRLF & _
/ app1/response5.asp clips

The best record = 7.05 ms / page
Response time = 7.63 ms / page
Difference = +0.58 ms (an increase of 8.5%)

The result is a slight decrease in performance, this may be due to an increase of string operations, text output is also increased.


According to the ASP output test results, we reach the following coding rules:

Avoid excessive use of embedded ASP.
Response.Write the statement as much as possible into a single statement.
Do not add CRLF to the package Response.Write.
If you want to format HTML output directly in the statement Response.Write followed by CRLF.

Asp Optimization Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.