|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
看下面两段小程序,先不运行,比较t1和t2用时:
Sub TestA1()
Dim R()
n = 60000
ReDim R(1 To n, 1 To 1)
[a:a] = ""
For i = 1 To n
R(i, 1) = "中国"
Next
t = Timer
Cells(1, 1).Resize(n) = R
t1 = Timer - t
[d1] = t1
End Sub
Sub TestA2()
Dim R() As String
n = 60000
ReDim R(1 To n, 1 To 1)
[a:a] = ""
For i = 1 To n
R(i, 1) = "中国"
Next
t = Timer
Cells(1, 1).Resize(n) = R
t2 = Timer - t
[d2] = t2
End Sub
再如:
Sub TestB1()
n = 10000
Set d = CreateObject("scripting.dictionary")
t = Timer
For i = 10000001 To 10000000 + n
d(i) = ""
Next
t1 = Timer - t
Set d = Nothing
[e1] = t1
End Sub
Sub TestB2()
n = 10000
Set d = CreateObject("scripting.dictionary")
t = Timer
For i = 10000001 To 10000000 + n
s = "" & i
d(s) = ""
Next
t2 = Timer - t
Set d = Nothing
[e2] = t2
End Sub
运行后会不会惊讶?谁能解释?
[ 本帖最后由 Zamyi 于 2010-11-29 17:35 编辑 ] |
|