Recommended: The code for the Max movie site to generate Rss feed Some time ago, in order to add Rss subscription function to my movie site, I wrote an ASP code that dynamically generates Rss Feed. I can't upload attachments, so I just pasted the code. It's not long anyway. Friends who use Max as movie site can use it directly. Change other types of sites.
ASP developers are constantly working to get better performance and scalability in their design projects. Fortunately, there are many books and sites that provide great advice on this. However, the basis of these suggestions is the conclusion drawn from the structure of the ASP platform work, and there is no measurement of the actual improvement in performance. Since these suggestions require more complex coding processes and reduce the readability of the coding, developers can only measure themselves whether it is worth paying to improve the performance of their ASP applications without seeing the actual operational effect.
This article is divided into two parts, and I will introduce some performance test results to help developers determine whether a particular initiative is not only worthwhile for future projects, but also able to update the original project. In the first part, I will review some basic issues in ASP development. In the second part, some optimization of ADO functions will be involved and their results will be compared with the ASP page that calls the VB COM object to execute the same ADO function. These results are eye-opening and sometimes surprising.
In this article, we will answer the following questions:
* What is the most efficient way to write content generated by ASP into the response stream?
* Should the buffer be turned on?
* Should I consider adding comments to the ASP code?
* Should the default language be explicitly set for the page?
* Should the Session state be turned off if not required?
* Should script logic be placed in subroutines and function areas?
* What are the effects of using include files?
* What kind of load will be applied when performing error processing?
* Does setting a context processing have any impact on performance?
All tests were conducted using Microsoft's Web Applications Focus Tool (WAST), a free tool that can be found here. I created a simple test script with WAST, repeatedly calling the ASP page test described below (more than 70,000 times each). The time of the reaction is based on the average last byte total time (TTLB), that is, from the time the initial requested time to the time the tool receives the last bit of data from the server. Our test server is a Pentium 166 with 196MB of memory and Pentium 450 with 256MB of memory. You may think that the performance of these machines is not very advanced, but don’t forget that we are not testing the capacity of the server, we are just testing the time it takes for the server to process one page at a time. These machines do not do other work during the test. WAST test scripts, test reports, and all ASP test pages are included in the ZIP file, and you can review and test it yourself.
What is the most efficient way to write content generated by ASP into the response stream?
One of the main reasons for using ASP is to generate dynamic content on the server. So it's obvious that the starting point of our test is to determine the most suitable way to send dynamic content to the response stream. Among the many options, two are the most basic: one is to use inline ASP tags, and the other is to use the Response.Write statement.
To test these choices, we create a simple ASP page where some variables are defined and their values are inserted into the table. While this page is simple and not very practical, it allows us to separate and test some separate questions.
Using ASP Inline Tags
The first test involves using an inline ASP tag <%= x %>, where x is an assigned variable. This method is by far the easiest to execute, and it keeps the HTML part of the page in a format that is easy to read and maintain.
| <% OPTION EXPLICIT 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 = [email protected] BirthDate = 1/1/1950 %> <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>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> |
Full code for /app1/response1.asp
Previous best (response rate) = 8.28 msec/page
Use the Response.Write statement on each line of HTML
Many better learning documents recommend avoiding the previous method. The main reason is that during the output page and the processing page applying reaction time, if the web server has to convert between sending pure HTML and processing scripts, a problem called context conversion occurs. When most programmers hear this, their first reaction is to wrap every line of the original HTML in the Response.Write function.
| … 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 fragment
Previous best (response rate) = 8.28 msec/page
Reaction time = 8.08 msec/page
Difference = -0.20 msec (reduction of 2.4%)
We can see that using this approach is very small in performance compared to using inline tagging, perhaps because the page loads the server with a bunch of small function calls. The biggest disadvantage of this approach is that since HTML is now embedded in scripts, the script code becomes more verbose and more difficult to read and maintain.
Share: 20 very useful examples in ASP programming (I) 1. How to use Asp to determine the virtual physical path of your website Answer: Use the Mappath method: < %= Server.MapPath()% >2. How do I know the browser used by the user? Answer: Use the Request object method:
5 pages in total Previous page 12345Next page