Re: stupid question
- From: "mayayana" <mayaXXyana1a@xxxxxxxxxxxxxxxx>
- Date: Sat, 10 May 2008 18:37:45 -0400
I don't think the point is to be able to "boast
of the best method". Personally I find optimizing very
interesting and useful. There's not a heck of a lot of
optimizing that can be done in script, but as a matter
of valuing good design and general mindfulness in one's
endeavors, I like to try to optimize wherever I can.
There's a very interesting site for VB optimizing that
compares different methods:
http://www.xbeat.net/vbspeed/
The differences can often be very significant in "real
world" usage. Unfortunately, though, while VB is a
somewhat inefficient tool that can be optimized to very
high efficiency, VBScript is a very inefficient tool that
can only be minimally optimized.
In the case at hand I doubt that, in most scenarios,
there will be a significant difference. On the other hand,
I didn't know exactly what the OP was doing...so why
not optimize? Why not try to understand how the code
works and be articulate about it?
I don't happen to have a list of 23,000 files handy, so
I don't know what the "insignificant" difference is that you
found. A couple points that might be relevant:
* A tiny difference in checking on one file could translate
into a notable difference if thousands of files need to be
checked against the list.
* I don't know how accurate the time method is for measuring
tiny durations. It may not even be accurate to 100 ms. I really
have no idea. But given that a single search of an array or string
is involved, extreme accuracy down to 1 ms would be needed
to assess real world implications.
It may be that there's virtually no difference, even where
tens of thousands of files are checked for tens of thousands
of names. Instr, array accessing, and string comparison are
all very fast. That result would still be interesting to know, as
far as I'm concerned. Isn't it more interesting to know the facts
than to know who gets "boasting rights"?
difference
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
on a list of 23000 fully qualified file names. Testing was done withlist.
nonexistent strings as well as lines found in various positions in the
to
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
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: Todd Vargo
- 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
- From: Todd Vargo
- Re: stupid question
- Prev by Date: Re: stupid question
- Next by Date: Re: stupid question
- Previous by thread: Re: stupid question
- Next by thread: Re: stupid question
- Index(es):
Relevant Pages
|