一直听说asp比其他语言的效率低,其实不然,效率低只是程序人员在开发的过程中的方法效率低而已,这与语言效率低没有关系。
在实际开发过程中,我发现asp一个效率低的地方,就是&连接符的效率低,但我们换个方法,也可以直接提高它的效率。我们比较一下下面的两种方法:
<%
class strCat
Private index, ub, ar()
Private Sub Class_Initialize()
'statements
redim ar(50)
index=0
ub=10
End Sub
Private Sub Class_Terminate()
'statements
erase ar
End Sub
public default Sub Add(value)
ar(index)=value
index=index+1
if index>ub then
ub=ub+50
redim preserve ar(ub)
end if
end sub
public Function display
redim preserve ar(index-1)
display=join(ar,"")
end function
end class
'方法一:使用&连接符
t1=timer
os=""
for i=1 to 10000
os=os & "www.aspbc.com"&i&" "
next
s=os
t2=timer
response.Write("<br>Using the fast string class: " &t2-t1 & "<hr>")
'方法二:使用自定义的类
t3=timer
set cat= new strCat
for i=1 to 10000
cat("www.aspbc.com")
next
s= cat.display
set cat = nothing
t4=timer
response.Write("<br>Using the fast string class: " &t4-t3 & "<hr>")
%>(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)
运行一下,看看输出的时间是不是相差很多倍。
