關於"&"運算符效率低下的問題,有什麼好的解決辦法? - 中國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 |