Maximum efficiency test results for ASP write response flow

Source: Internet
Author: User
Response | In response to this tutorial, the most effective way to write ASP-generated content into the response stream is to test the efficiency of Response.Write and <%=%> output content to the client.


One of the most important reasons for using ASP is to generate dynamic content on the server. So obviously, the starting point of our testing is to determine the most appropriate way to send dynamic content to the response stream.

Of the many choices, two are most basic: one is using inline ASP tags and the other is using Response.Write statements.

To test these choices, we created a simple ASP page that defines the variables and then inserts their values into the table. Although this page is very simple and not very practical

, but it allows us to isolate and test some separate issues.

Using ASP inline markup

The first test includes using the inline ASP tag <%=x%&gt, where x is an assigned variable. So far, this method is the easiest to execute, and it makes the HTML part of the page

Maintain a format that is easy to read and maintain.

<%
OPTION EXPLICIT ' This function is to force the use of each variable before you must first define

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 = "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"
%>

<HTML>
<HEAD>
<title>response test</title>
</HEAD>
<BODY>
<TABLE>
<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 >
</TABLE>
</BODY>
</HTML>

Complete code for/app1/response1.asp

Previous best (reaction speed) = 8.28 msec/page

Use the Response.Write statement on every line in the HTML

Many of the better learning documents suggest avoiding using the previous approach. The main reason for this is that in the process of outputting pages and processing pages, if the Web server does not

A problem called context conversion occurs if you do not convert between sending pure HTML and processing scripts. When most programmers hear this, their first reaction is to move the original

Each line of HTML is wrapped in the Response.Write function.

...

Response.Write ("
Response.Write ("
Response.Write ("<title>response test</title>")
Response.Write ("
Response.Write ("<body>")
Response.Write ("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>")

...

Fragments of/app1/response2.asp

Previous best (reaction speed) = 8.28 msec/page

Reaction time = 8.08 Msec/page

difference = -0.20 msec (Decrease 2.4%)

We can see that this is a very small gain in performance compared to the method of using inline markup, perhaps because the page loads a bunch of small functions on the server

Call. The biggest disadvantage of this approach is that since HTML is now embedded in the script, the scripting code becomes more verbose and harder to read and maintain.

Using wrapper functions

When we try to use the Response.Write statement this method, the most frustrating discovery may be that the Response.Write function cannot place a CRLF at the end of each line.

So when you read the source code from the browser, the HTML, which was nicely decorated, is now a line that has no end. I think your next discovery may be more frightening:

The Response object does not have its sister function Writeln. So, one obvious response is to create a wrapper function for the Response.Write function so that each row is appended with a

A CRLF.

...

WRITECR ("<tr><td><b>first name:</b></td><td>" & FirstName & "</td" ></tr> ")

...

SUB WRITECR (str)

Response.Write (Str & VbCRLF)

End SUB

Fragments of/app1/response4.asp

Previous best (reaction speed) = 8.08 msec/page

Reaction time = 10.11 Msec/page

difference = +2.03 msec (Increase 25.1%)

Of course, since this method effectively doubles the number of function calls, its impact on performance is obvious, so avoid at all costs. The irony is that CRLF also reacts

The stream adds 2 bytes to each line, which the browser does not need to render to the page. Everything you've done with well-formed HTML is making it easier for your competitors to read your HTML source code.

and understand your design.

Connecting consecutive Response.Write to a single statement

The next logical step, regardless of the test we used in the wrapper function, is to extract all the strings from a separate Response.Write statement and connect them to the

A single statement, which reduces the number of function calls and greatly improves the performance of the page.

...

Response.Write ("""<title>response test</title >" &_
""<body>" &_
""<table>" &_
"<tr><td><b>first name:</b></td><td>" & FirstName & "</td></tr



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.