"VBA.len" is 4 times slower than "len" (?!)

Viewed 60

I measured the speed of this code and was surprised by the results after removing the "VBA.":

Sub speed_test()
    Dim i As Long, str As String
    'timer_start
    For i = 1 To 1000000
        If VBA.Len(str) = 0 Then  ' vs If Len(str) = 0 Then
        End If
    Next
    'timer_stop
End Sub

Using "VBA.Len" it takes 0,040 seconds while using just "Len" it takes 0,010 seconds!

This page Why do Len and VBA.Len return different results? make me think that it's not just the specification of "VBA." to cause the difference. It seems more like they are two different functions doing something different.

I get identical 4x speed difference comparing "VBA.LenB" to "LenB" while I don't see speed difference comparing "VBA.Left$" to "Left$".

How can "VBA.Len" vs "Len" be different?

I always used to add "VBA." in calling internal VBA function as for good practice of specifying the library. Should we abandon this practice after this particular discovery?

0 Answers
Related