|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
ASP一般认为只能运行在IIS上,正如前面所提到的,这并不是十分正确,事实上,ASP也能运行在Apache上。Apache ASP可在任意Apache服务器上运行有限的ASP功能,所需做的,只需打开mod_perl。速度|优化 Memory and Speed Optimization with ASP - Part I
It is an 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 you any ASP page, while the HTML pages were correctly displayed. One of the challenges faced by the web developers is how to create a fast (usually a faster that the one you have) application out of a series of HTML and ASP pages.
When programming ASP pages, memory and speed optimization can be acquired in two different ways. Because HTML pages are not processed at the server-side, we will talk more about memory and speed optimization of ASP pages:
By programming good ASP pages. This article is all about optimizing by writing good ASP pages.
By configuring the web server. We will cover this topic in another article.
When talking about optimizing ASP pages, we 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 you 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 only available type is VARIANT type. All the variables declared in ASP are of type VARIANT . Unfortunately, this makes all the operations slower, because the work with VARIANT is slower. The system has to first evaluate the type of the variant, convert it to the most appropriate of the operation that is to be 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, strings, 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 that use them to store data. As little as you use arrays, you should have in mind the following way of optimizing array access:
Arrays are made from continuous blocks of memory. Reading and writing an item of an array is slower than accessing a simple variable. For each access to an item in an array, the runtime environment has to determine the position of the item in the memory, based on the first element of the array and the index. Therefore, it's faster to read/write a variable, than an array item. Therefore, if you need to use the same array item in a loop repeatedly, you'd better assign the item to a variable and use that variable instead.
E.g. :
<%
' this will calculate for each element, the value a(i) = 2i ( = 2 * 2 * 2 - for i times)
Dim a(20) ' 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 slow when compared to accessing items in single dimensional arrays. Think about this when 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 10 by 10 matrix, try to use a 100-element array to speed up access. In this case, you have to manually find your items in the array. If you use i and j as indices, and you used to access an element like A(i, j), the new way of accessing the items will 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 is the way in which ASP allocates and uses memory.
1. Dim A (10) ' declaration of static array with 10 elements
Access to its i</p> ASP在国内异常流行,因为国内大多使用的是盗版的Windows和盗版的SQLServer,而ASP+COM+SQLServer实际上也是一种不错的搭配,其性能也不输于PHP+MYSQL,特别是Windows系统和SQLServer都有图形界面,比APACHE和MYSQL易于维护,因此对于不重视知识产权的国家来说也是一种不错的选择。 |
|