[VB] 到底時間拖在哪裡
簡單的來說, 就是物件類別產生後, 時間到底慢在哪?
時間表如下, 由物件類別完成 Value 設定, 但是到 Form_GotFocus 卻越拖越長...
nPoint Form_Load (s) Form_GotFocus (s)
-----------------------------------------------
1,000 0 0.109375
10,000 0.269513 5
20,000 0.5507813 32.23828
100,000 25.48252 不明 (等了四分鐘只好強迫中斷)
-----------------------------------------------
測試環境:
CPU: Pentium II 300, SVGA: S680/4MB, DRAM: 64 MB, OS: Win98c SE, VB5 SP3
測試程式碼如下:
-- cPoint.cls -- 自訂物件類別模組
Public x As Double
Public y As Double
Public z As Double
----------------
-- Form1.frm -- 測試用, Form1 畫面上未佈置任何物件
Private st
Private Sub Form_GotFocus()
Debug.Print Timer - st
End Sub
Private Sub Form_Load()
nPoint = 20000
st = Timer
ReDim cP(1 To nPoint) As New cPoint
For i = 1 To nPoint
With cP(i)
.x = Rnd
.y = Rnd
End With
Next i
Debug.Print Timer - st
st = Timer
End Sub
------------------