我已用速记符号声明了一个整数变量testInt,如下所示
Dim testInt%
使用
之间是否存在任何差异somevalue = testInt * testInt
与
somevalue = testInt% * testInt%
简而言之,在引用变量的每个点上使用类型说明符是否有优势?
答案 0 :(得分:5)
快速时间测试显示他们是直线球 - 直觉上很有意义
使用Long
而不是Integer
会更有效率。见MSFT Link
我将使用更准确的API计时器
重复此操作Sub B()
Dim testInt%
Dim somevalue%
Dim lcnt As Long
Dim dbStart As Double
dbStart = Timer()
For lcnt = 1 To 100000000
somevalue = testInt * testInt
Next
MsgBox "Time was " & Timer() - dbStart
End Sub
Sub A()
Dim testInt%
Dim somevalue%
Dim lcnt As Long
Dim dbStart As Double
dbStart = Timer()
For lcnt = 1 To 100000000
somevalue = testInt% * testInt%
Next
MsgBox "Time for type-specified was " & Timer() - dbStart
End Sub