Re: stupid question

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



mayayana wrote:

OTOH: His delimited approach seems a bit lackluster. (no disrespect to
mayayana)

That's a good point. I guess it would need a delimiter
on both ends.

No comment as to which method is faster though.<shrug>

I imagine that the array check is plenty fast for most uses,
but the OP referred to a "huge" number of folder names to
check, so I thought it might be worth his while to optimize
the operation. I figure that the bigger the number, the better
the string method. My reasoning is that once the delimited string
has been created, all folder names can be filtered with one
case-insensitive InStr, which is nearly instant no matter how
big the string gets. With the array method, on the other hand,
each folder name requires a separate binary comparison and
probably two calls to UCase.

Ok, you forced me to comment...

Based on your "once the delimited string has been created" comment, my
testing of InStr to the Ucase(array) method after variable/array is in
memory, the comparison seems to evaluate to an insignificant time difference
on a list of 23000 fully qualified file names. Testing was done with
nonexistent strings as well as lines found in various positions in the list.

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("list.txt", 1)
MyArray = Split(f.ReadAll, vbCRLF)
s = "*" & Join(MyArray, "*") & "*"
f.Close
Wscript.Echo "Array and variable are now in memory..."

name = "some text to find in list"

'Array Method
begin = time
found = false 'initialize flag
For i = Lbound(MyArray) To Ubound(MyArray)
If Ucase(name) = Ucase(MyArray(i)) Then
found = true 'item was found so toggle flag
Exit For 'and abort the search
End If
Next
Wscript.Echo "Array Method", time - begin

'InStr Method
begin = time
If Instr(1, s, "*" & name & "*", 1) > 0 then
'-- there's a match
End if
Wscript.Echo "Instr Method", time - begin


Based on my testing results, how "huge" does the list need to be for one to
explore code optimization? Likewise, how significant does the difference
need to be for one to boast one method over another?

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

.



Relevant Pages

  • Re: Surprise in StrConv using vbProperCase
    ... > Your code will capitalize the first letter of a string. ... Use Split(string into array of words using blank as delimiter); ...
    (microsoft.public.access.modulesdaovba)
  • Re: Encoding Question
    ... > You receive a byte array from a socket. ... > a string with the following function, then splitting the string by the ... > delimiter sub-string. ... I have a similar problem reading in a file that can have various delimiters, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ubound behavior with Split vs. ReDim
    ... > Dim Array() as String ... TextToSplit = Replace$(TextToSplit, Delimiter, Chr$(1)) ...
    (microsoft.public.vb.general.discussion)
  • Re: passing a string to a C++ function
    ... identity function which adds the emails to the encryption process. ... //I set this with each item of the array as it loos and call my function ... terminated string, and it returns to me the encrypted message ... //this will ALWAYS be the delimiter ...
    (microsoft.public.vc.language)
  • Re: Surprise in StrConv using vbProperCase
    ... > Your code will capitalize the first letter of a string. ... Use Split(string into array of words using blank as delimiter); ...
    (microsoft.public.access.modulesdaovba)