View Single Post
 
Old October 8th, 2003, 11:21 AM
owain owain is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code I tried was thus:

Code:
Private Declare Function GetTickCount& Lib "kernel32" ()

Private Sub Form_Load()

Dim lngCount                        As Long
Dim lngNoFiles                      As Long
Dim lngNoDlls                       As Long
Dim strTemp                         As String
Dim lngTickCount                    As Long

    lngTickCount = GetTickCount
    lngNoDlls = 0
    lngNoFiles = 0
    For lngCount = 1 To 50
        strTemp = Dir("C:\WINDOWS\System32\*.*")
        Do Until strTemp = ""
            lngNoFiles = lngNoFiles + 1
            If InStr(1, LCase(strTemp), "dll", vbTextCompare) > 0 Then
                lngNoDlls = lngNoDlls + 1
            End If
            strTemp = Dir()
        Loop
    Next
    Debug.Print "Files: " & lngNoFiles & _
        " DLL's: " & lngNoDlls & _
        " Time: " & GetTickCount - lngTickCount & _
        "ms Average: " & (GetTickCount - lngTickCount) / lngNoFiles & "ms"

    lngTickCount = GetTickCount
    lngNoDlls = 0
    lngNoFiles = 0
    For lngCount = 1 To 50
        strTemp = Dir("C:\WINDOWS\System32\*.*")
        Do Until strTemp = ""
            lngNoFiles = lngNoFiles + 1
            If LCase(strTemp) Like "*dll*" Then
                lngNoDlls = lngNoDlls + 1
            End If
            strTemp = Dir()
        Loop
    Next
    Debug.Print "Files: " & lngNoFiles & _
        " DLL's: " & lngNoDlls & _
        " Time: " & GetTickCount - lngTickCount & _
        "ms Average: " & (GetTickCount - lngTickCount) / lngNoFiles & "ms"
    Unload Me
    End

End Sub
On my PC this gave me the following results:

Code:
Files: 119400 DLL's: 66050 Time: 1842ms Average: 0.015427135678392ms
Files: 119400 DLL's: 66050 Time: 1612ms Average: 0.013500837520938ms
Meaning that using Like is approximately 14% faster than InStr (or did I do that sum the wrong way round?)

Regards
Owain Williams