Private Declare Function WWindowsStart Lib "WINMM" Alias "timeGetTime" () As Long
Function Test2()
Dim lngStartA As Long, lngStopA As Long, lngResultA As Long
Dim lngStartB As Long, lngStopB As Long, lngResultB As Long
Dim strMainText As String, lngCounter As Long
Dim booPointless As Boolean
strMainText = "Rabbit"
lngStartA = WWindowsStart
For lngCounter = 1 To 100000
booPointless = IIf(strMainText Like "R*", True, False)
Next lngCounter
lngStopA = WWindowsStart
lngStartB = WWindowsStart
For lngCounter = 1 To 100000
booPointless = IIf(Left$(strMainText, 1) = "R", True, False)
Next lngCounter
lngStopB = WWindowsStart
lngResultA = lngStopA - lngStartA
lngResultB = lngStopB - lngStartB
If lngResultA = lngResultB Then
MsgBox "They are the same.", vbInformation
ElseIf lngResultA < lngResultB Then
MsgBox "Like 'Text*' is faster than Left$(Text, 1) = Text'" & _
vbCrLf & "A: " & lngResultA & " milliseconds" & _
vbCrLf & "B: " & lngResultB & " milliseconds", vbInformation
Else
MsgBox "Left$(Text, 1) = Text' is faster than Like 'Text*'" & _
vbCrLf & "A: " & lngResultA & " milliseconds" & _
vbCrLf & "B: " & lngResultB & " milliseconds", vbInformation
End If
End Function
Function Test1()
Dim lngStartA As Long, lngStopA As Long, lngResultA As Long
Dim lngStartB As Long, lngStopB As Long, lngResultB As Long
Dim strMainText As String, lngCounter As Long
Dim booPointless As Boolean
strMainText = "Rabbit"
lngStartA = WWindowsStart
For lngCounter = 1 To 100000
If strMainText Like "R*" Then booPointless = True
Next lngCounter
lngStopA = WWindowsStart
lngStartB = WWindowsStart
For lngCounter = 1 To 100000
If Left$(strMainText, 1) = "R" Then booPointless = True
Next lngCounter
lngStopB = WWindowsStart
lngResultA = lngStopA - lngStartA
lngResultB = lngStopB - lngStartB
If lngResultA = lngResultB Then
MsgBox "They are the same.", vbInformation
ElseIf lngResultA < lngResultB Then
MsgBox "Like 'Text*' is faster than Left$(Text, 1) = Text'" & _
vbCrLf & "A: " & lngResultA & " milliseconds" & _
vbCrLf & "B: " & lngResultB & " milliseconds", vbInformation
Else
MsgBox "Left$(Text, 1) = Text' is faster than Like 'Text*'" & _
vbCrLf & "A: " & lngResultA & " milliseconds" & _
vbCrLf & "B: " & lngResultB & " milliseconds", vbInformation
End If
End Function