Let ASP improve the execution speed

xiaoxiao2021-03-05  25

One of the skills: improve the efficiency of using the Request collection

Access an ASP collection to extract a value of time, occupying the process of computing resources. Because this operation contains a series of searches for related collections, this is more than access

A local variable is much slower. Therefore, if you intend to use a value in the Request collection multiple times in the page, you should consider storing it into a partial variable.

For example, write code into the following form to speed up the script engine processing speed:

Strtitle = Request.form ("Title")

StrfirstName = Request.form ("firstname")

StrlastName = Request.form ("Lastname")

If len (strtitle) kil = strtitle & "

If strfirstname = "" "" "" & strlastname

Elseif len (strfirstname) = 1 THEN

Strfullname = startle & strfirstname & "." & strlastname

Else

Strfullname = starte & strfirstname & "& strlastname

END IF

Second: Direct access to the appropriate collection

If you don't have no choice, don't use this form of strpage = request ("page") to get parameters because this will search all the collection in order -

QueryString, Form, Cookies, ClientCertificate, ServerVarible until the name of the first match value is found. This is better than direct access

When the collection efficiency is low, it is unsafe, unless it is absolutely guaranteed that this value does not appear in another collection.

For example, you may want to search for the web server name that meets the customer request, which is looking for in the Request.ServerVarables collection in each query.

"Server_name" is implemented. However, if other collections also include values ​​called "Server_name" (key names are not case sensitive), when using Request

("Server_Name"), the error result is obtained. All in all, the appropriate collection should be accessed directly as much as possible.

Tips 3: Use the response.isclientConnected property before the time of operation

Use response.isclientConnected is a useful way to observe whether users are still connected to the server and being loaded into the ASP creation. If the user is disconnected

Or stop downloading, we don't have to waste the resources of the server to create a web page, because the buffer content will be discarded by IIS. So, for those who need a lot of time calculations or

Resources use more web pages, it is worth checking if the tourists have been offline at each stage:

... code to create first part of the page

If response.isclientconnected the

Response.flush

Else

Response.end

END IF

... Code to create Next Part of Page

Tips 4: Optimize ADO operation in ASP

Usually, the data constitutes the actual content of the web site. Therefore, optimize the ADO operation to accelerate the ASP code execution, very useful: a. Select only the required columns: When opening the ADO record set, unless you need to get all the columns, you should not automatically use the table name (ie SELECT *) . Alone

The specifier will reduce the amount of data sent to the server or from the server. Even if you need to use all columns, naming separately alone will get the best sex.

Can, because the server does not have to explain the names of these columns.

b. Use the stored procedure as much as possible. The stored procedure is a pre-compiled program that contains a ready-made execution plan, so performing faster than the SQL statement.

c. Use the appropriate cursor and lock mode. If all the jobs are just read data from the record set, then display it on the screen, then use the default

Only the recording set of read-only. The less work is used to maintain the details of the record and lock, the higher the performance.

d. Use the object variable. When traversing a record set, a method that can improve performance is to use object variables to point to members in the collection. E.g:

While Not Rsgc.eof

Response.write "Project Name:" & RSGC ("GCMC") & "(Project Code:" & RSGC ("gccode")

& ")

"

RSGC.MOVENEXT

Wend

You can use the code to be rewritten to speed up:

SET GCMC = RSGC ("GCMC")

Set gccode = rsgc ("gccode")

WHILE NOT RSGC.EOF Response.Write "project name:" & gcmc & "(Project Code:" & gccode & ")

RSGC.MOVENEXT

Wend

The new code establishes a reference to object variables, so you can use object variables instead of actual variables, which means that the work of the script is reduced because

The number of times the index is less.

Skill 5: Don't mix the scripting engine

We know that you can use VBScript in the ASP page or JScript. But when using JScript and VBScript simultaneously on the same page,

feasible. Because the server must instantiate and try cache two (rather than one) script engine, this increases the system burden to some extent. Therefore, from sex

Can be considered and a variety of script engines should not be mixed on the same page.

转载请注明原文地址:https://www.9cbs.com/read-35689.html

New Post(0)