13 September 2002

You can enhance your websites performance by using "option explicit" at the beggining of your ASP(VBScript) scripts. When we use Option explicit it forces us to dimension all our variables. It wil throw an error if it finds a variable that has not been declared (dimensioned). Dimensioning your variables causes them to be referenced by an ordinal number. Variables which are not dimensioned are referenced by their name. Referencing variables by ordinals is 200%-300% faster than referencing them by name. I determined these numbers by comparing the execution times of the two scripts below.

If you would like to reproduce the experiment the process is very straight forward. Place each script in a seperate ASP page(file). Place the asp pages on your web server. Load the web pages in your browser alternating between the pages. I prefer alternating between the pages because it reduces the chance that outside factors cause one page to execute more slowly than the other. This experiment is accurate , but not very precise . Have a pencil and paper ready (or your favorite editor) to record the length of time it takes each script to execute. Execute the scripts five times each (a total of ten times alternating) and compare your results.

Using Option Explicit

<%@ Language=VBScript %>

<%
OPTION EXPLICIT Dim DimI, DimVariable response.write now() response.write "
" FOR DimI = 0 to 9000000 DimVariable = DimI NEXT response.write now() response.write "
"
Without Option Explicit

%>
<%
@ Language=VBScript %>
<%
response.write now() response.write "
" FOR noDimI = 0 to 9000000 noDimVariable = noDimI NEXT response.write now() response.write "
" %>

Less Is More ~ Older posts are available in the archive.