Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2003, 11:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default performance question..

hi all..

i want to know if somebody did a performance test around this issue..

im looking for string that have a constant substring inside them..

i have to ways to do it:
strcomp
and
string like "*mystr"

do anybody know what's best practice for it??

thanks in advance...


Gonzalo Bianchi
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old September 17th, 2003, 12:32 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you considered instr or instrrev? I think that is the most efficient.
 
Old September 17th, 2003, 02:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

sorry.. strcomp was really instr.. do you have any test about them???

thanks..

Gonzalo Bianchi
 
Old September 17th, 2003, 02:19 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I haven't done any formal bechmarking, but if I remember correctly instr is more efficient than regular string comparison.
 
Old September 17th, 2003, 08:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Gonzalo,

I did do some benchmarks some time ago and I found out
that, at least in my cases, the like operator was a 10%
slower than instr, but I did not spend that much time.
I though that because like is more powerful, there is
a penalty using it. But I can be wrong... Use GetTickCount
and iterate some thousand times both instr and like
using some of your data and check the difference.
GetTickCount is not that precise, do more than one run until
you get a stable number, and iterate enough time to get
a difference in time of at least one second.
I will be interested to know the results.

Marco

Quote:
quote:Originally posted by gbianchi
 hi all..

i want to know if somebody did a performance test around this issue..

im looking for string that have a constant substring inside them..

i have to ways to do it:
strcomp
and
string like "*mystr"

do anybody know what's best practice for it??

thanks in advance...


Gonzalo Bianchi
 
Old October 8th, 2003, 10:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

i made some test between instr and like..
but i get no diference between then :(

well.. i try this..

Code:
Option Explicit
Dim fso As FileSystemObject
Dim fDir As Folder
Dim fArch As File
Dim sTime As Date
Dim nTotal As Long
Dim nHits As Long
Dim i As Long
Private Sub CmdCheck1_Click()
    nTotal = 0
    nHits = 0
    sTime = Now
    For i = 1 To 50
        For Each fArch In fDir.Files
            nTotal = nTotal + 1
            If InStr(1, LCase(fArch.Name), "dll", vbTextCompare) > 0 Then
                nHits = nHits + 1
            End If
        Next fArch
    Next i
    TxtTiempo.Text = DateDiff("s", sTime, Now)
    TxtTotal = CStr(nHits) & " / " & CStr(nTotal)
End Sub

Private Sub Command1_Click()
    nTotal = 0
    nHits = 0
    sTime = Now
    For i = 1 To 50
        For Each fArch In fDir.Files
            nTotal = nTotal + 1
            If LCase(fArch.Name) Like "*dll*" Then
                nHits = nHits + 1
            End If
        Next fArch
    Next i
    TxtTiempo1.Text = DateDiff("s", sTime, Now)
    TxtTotal1.Text = CStr(nHits) & " / " & CStr(nTotal)
End Sub

Private Sub Form_Load()
    Set fso = New FileSystemObject
    Set fDir = fso.GetFolder("C:\WINNT\system32")
End Sub
i use two buttons and 4 textboxes for displaying reasons...

and instr return 190 and like 191... no real dif...

could somebody else try it to see what results it have??


Gonzalo Bianchi
 
Old October 8th, 2003, 11:21 AM
Friend of Wrox
 
Join Date: Jun 2003
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on scalability and performance ThanhD BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 April 17th, 2007 02:13 PM
indexing performance question BinFrog SQL Server 2000 1 February 23rd, 2005 11:47 PM
query performance question kBusby Oracle 3 February 14th, 2005 04:42 PM
Ado.net performance question (SQL server vs OleDB spamp ADO.NET 1 August 2nd, 2004 10:37 AM
Performance Question Kenny Alligood VB Databases Basics 2 August 11th, 2003 08:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.