Re: stupid question
- From: "Todd Vargo" <tlvargo@xxxxxxxxxxxxxx>
- Date: Sat, 10 May 2008 17:48:37 -0400
mayayana wrote:
OTOH: His delimited approach seems a bit lackluster. (no disrespect toThat's a good point. I guess it would need a delimiter
mayayana)
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)
.
- Follow-Ups:
- Re: stupid question
- From: mayayana
- Re: stupid question
- References:
- Re: stupid question
- From: Todd Vargo
- Re: stupid question
- From: preet
- Re: stupid question
- From: Joe Fawcett
- Re: stupid question
- From: Todd Vargo
- Re: stupid question
- From: mayayana
- Re: stupid question
- Prev by Date: Re: Domain connection detection
- Next by Date: Re: stupid question
- Previous by thread: Re: stupid question
- Next by thread: Re: stupid question
- Index(es):
Relevant Pages
|