关于"&"运算符效率低下的问题,有什么好的解决办法? - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- 关于"&"运算符效率低下的问题,有什么好的解决办法? (http://www.webasp.net/article/8/7887.htm) |
| -- 作者:未知 -- 发布日期: 2003-11-15 |
| 大家看看。
我们知道用“ & ”号比用“+”号快。因为“+”要对字符窜变量做类型判断并转换。 当时也没想出什么好办法。只是将两次“&”运算拆开,速度提了一倍。还是解决不了问题。 结果就是:for i 1 to 5000 ,i以字符形式相加。用&运算,要600-800ms 现在试试下面这个。建了个CStrCat的类。 <% PageExeTime1=Timer * 1000 '计时开始 Set sc=new CStrCat For i=0 To 5000 sc.add i next response.write sc.value '计时结束 Response.Write ",Processed time:" & fix(abs(CDBL(Timer)*1000 - PageExeTime1))&"ms</font></p>" %> <% Class CStrCat '这是类开始。 Private i,sa() Public Property Get Value redim preserve sa(i) Value=Join(sa,"") End Property Private Sub Class_Initialize() i=clng(0) redim sa(500) End Sub Private Sub class_terminate() erase sa End Sub Public function Add(ps) if len(ps)=0 Then Exit function if (i>=ubound(sa)) Then upsize sa(i)=ps i=i+1 End function Private Sub upsize() Dim u u=ubound(sa) redim preserve sa(clng(u+u*0.1)) End Sub End Class %> |
| webasp.net |