ASP memory and speed optimization, the first part (English version)

Source: Internet
Author: User
Tags arrays integer variables
Speed | Optimized Memory and Speed optimization with Asp-part I
It is a all to familiar problem:optimizing the memory and speed of your Web sites. Maybe you have been, more than once a week, in the situation where your Web server stopped giving your any ASP page The HTML pages were correctly displayed. One of the challenges faced by the Web developers are how to create a fast (usually a faster this one you have) Applica tion out of a series of HTML and ASP pages.

When programming ASP pages, memory and speed optimization can is acquired in two different. Because HTML pages are not processed at the Server-side, we'll talk more about memory and speed of ASP page S

By programming good ASP pages. This article are all about optimizing by writing good ASP pages.
By configuring the Web server. We'll cover this topic in another article.
When talking about optimizing ASP pages, we are should start from the deepest level:basic variables.

One of the biggest differences between Visual Basic (VB) and ASP programming is the variable declaration. VB is a programming language, so can define variables of a specific type:

Dim I As Integer ' integer declaration
Dim a$ ' String declaration
Dim objmycom As object ' object declaration
Dim var As Variant ' variant declaration

While ASP is a scripting language, where the available type is VARIANT type. The variables declared in ASP are of type VARIANT. Unfortunately, this makes all the operations slower, because the work with a VARIANT is slower. The system has to the "type of" the variant, convert it to the most appropriate of the operation this is to B e done, and then make the operation.

VARIANT is a very smart type of variable. It has great capabilities of storing EMPTY and NULL values, along with any types of data, such as (integers, doubles, stri NGS, currency and dates, arrays or objects).

Optimizing memory and speed when working with ARRAYS.
ASP programmers are usually not very good friends with ARRAYS. Using ARRAYS is more common to VB programmers which use them to store data. As little as your use arrays, for should have in mind the following way of optimizing array access:

Arrays are made from continuous blocks of memory. Reading and writing an "an" is slower than accessing a simple variable. For each access to a item in an array, the runtime environment has to determine the position of the item in the memory, b Ased on the the the array and the index. Therefore, it ' s faster to read/write a variable, than an array item. Therefore, if you are need to use the same array item in a loop repeatedly, your ' d better assign the item to a variable and use that variable instead.

e.g.:

<%
' This'll calculate for each element, the value a (i) = 2i (= 2 * 2 * 2-for i)
Dim A () ' The array
Dim i,j ' indexes
Dim TempVar ' a temporary variable
' Non-optimized Array Access:
For i = LBound (a) to UBound (a)
A (i) = 1
For j = 2 to I
A (i) = A (i) * 2
Next J
Next
' Optimized Array Access
For i = LBound (a) to UBound (a)
TempVar = 1
For j = 2 to I
TempVar = TempVar * 2
Next J
A (i) = TempVar
Next
%>

Because of the way of calculating the position of an element in memory, access to items in bidimensional arrays is very SL ow when compared to accessing the items in single dimensional arrays. I'm designing your algorithms.

A good way of optimizing speed of multidimensional arrays is to reduce them to a single dimensional array. Instead of using a by-matrix, try to use a 100-element array to speed up access. In this case, your have to manually find your items in the array. If with I and J as indices, and you used to access A element like A (i, J), the new way of accessing the items would be A ((i*10) + j), where I and J are the original indices.

In ASP there are few ways of declaring arrays. The difference between the declaration method are the way in which ASP allocates and uses.

1. Dim A (A) ' declaration of static array with elements


Access to its I



Related Article

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.