我們知道用“ & ”號比用“+”號快。因為“+”要對字符竄變量做類型判斷并轉換。
當時也沒想出什么好辦法。只是將兩次“&”運算拆開,速度提了一倍。還是解決不了問題。 結果就是:for i 1 to 5000 ,i以字符形式相加。用&運算,要300-500ms
現(xiàn)在試試下面這個。建了個CStrCat的類。
程序代碼: 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
你可以用這個代碼測試一下性能分別:
程序代碼: <% PageExeTime1=Timer * 1000 '計時開始 Set sc=new CStrCat For i=0 To 5000 sc.add i&"aaaaaa" next response.write sc.value
'計時結束 Response.Write ",Processed time:" & fix(abs(CDBL(Timer)*1000 - PageExeTime1))&"ms</font></p>"
PageExeTime2=Timer * 1000 For i= 0 To 5000 sc2=sc2&i&"aaaaaa" Next response.write sc2 '計時結束 Response.Write ",Processed time:" & fix(abs(CDBL(Timer)*1000 - PageExeTime2))&"ms</font></p>" %>
|