我把代码补全了测试结果是:IDE环境下运行Abs函数效率更高(1.4S左右,另一种方法1.7S左右),
编译后Abs函数效率更低了(0.35S左右,另一种方法0.15S左右)
@wmf2014回答得没错
现在问题来了,为什么IDE环境和编译后,两段代码执行的效率居然相反呢?
测试代码:
Private Sub Command1_Click()
Dim t As Double, a As Long, b As Long, i As Long
a = -1234
t = Timer
For i = 0 To 100000000
b = a
If a < 0 Then b = 0 - a
Next
MsgBox Timer - t
End Sub
Private Sub Command2_Click()
Dim t As Double, a As Long, b As Long, i As Long
a = -1234
t = Timer
For i = 0 To 100000000
If a < 0 Then
b = Abs(a)
Else
b = a
End If
Next
MsgBox Timer - t
End Sub