I have always written ASP programs casually, without much consideration for operating efficiency. ASP is quite tolerant to syntax and has high fault tolerance. It can be used directly without defining variables. Variable names do not need to distinguish between upper and lower case letters. ASP file names are also not as sensitive to upper and lower case letters as JSP. Therefore , among the many languages I have come into contact with, asp is the least strict one and the one with the lowest requirements for programmers.
Yesterday I tested the running speed comparison of asp.net, php and asp. Today I had the urge to see how much impact defined variables and undefined variables have on the running efficiency of asp. The results are surprising. The asp program defines variables better than undefined variables. Variables are twice as fast!
The test program is still the same as yesterday, running the for loop 10 million times to obtain the execution time.
1. The program does not define variables (dim i)
Copy the code code as follows:
<%
dim startime
startime=timer()
for i = 1 to 10000000
next
dim endtime
endtime=timer()
response.Write page execution time: & FormatNumber((endtime-startime)*1000,3) & milliseconds
%>
2. The program defines variables (dim i)
Copy the code code as follows:
<%
dim i
dim startime
startime=timer()
for i = 1 to 10000000
next
dim endtime
endtime=timer()
response.Write page execution time: & FormatNumber((endtime-startime)*1000,3) & milliseconds
%>
Each program is executed 5 times (except for the first execution), and then the average value is taken. The following are the test results:
Define variables | Execution time | average time | ||||
no | 1890ms | 1859ms | 1844ms | 1875ms | 1859ms | 1865ms |
yes | 890ms | 890ms | 984ms | 875ms | 890ms | 905ms |
From the above test results, it can be seen that the execution speed of asp is twice as fast when defining variables than not defining variables.
As for why this is the case, I have not studied it further. However, through this example, I really feel that standardized programming can make the program run more efficiently. For non-standard programming, although the language itself is fault-tolerant, the analysis process takes time. Of course, for a simple program, the difference in time between standardization and non-standardization may be minimal, but if the system you develop is relatively large, with many pages and function calls, then the difference between standardization and non-standardization will be negligible. The difference in time consumption will be highlighted, ranging from 1 or 2 times to dozens of times. It is not surprising.