软件教程

提高字符串的连接符&的效率

来源: 本站    类别: 软件教程    日期: 2015/12/7

 

一直听说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>")

%>

相关文章


Copyright © 2004 - 2024 CNHWW Inc. All Rights Reserved
石家庄市征红网络科技有限公司版权所有 邮政编码:050051
服务电话:0311-85315152 13931185013 在线客服QQ:81447932 / 81447933 邮箱: cnhww@163.com