Re: Performance Question

From: MikeD (nobody_at_nowhere.edu)
Date: 09/22/04


Date: Tue, 21 Sep 2004 21:13:52 -0400


"Bob O`Bob" <filterbob@yahoogroups.com> wrote in message
news:e1SvfeDoEHA.3392@TK2MSFTNGP15.phx.gbl...
> MikeD wrote:
>
>
> > Redimming, especially with the Preserve keyword, it extremely
inefficient.
> > It's almost always better to Redim as few times as possible. If I
> > understand right, a CR is your delimitter. You shouldn't have to loop
> > through the string twice. You can get the number of elements you'll
need by
> > something like this:
> >
> > UBound(Split(mystring, vbCr)) + 1 'add 1 because array is 0-based
>
>
> don't you think it's a little silly to say that you're going to cut down
> on the number of times looping through the data, and then call Split()
> (which ... loops through the data!), only to throw away its results?

No. Split is more efficient than actually looping through the string. Ken
is currently considering looping through the entire string once (parsing it
as he loops through it) just to get the number of elements needed (IOW, to
know what he needs to dim the array to); and then looping through it a
second time (parsing it yet again) to assign the data to the array. Using
Split is more efficient than doing that.

Do YOU know exactly how Split operates behind the scenes? I'll admit that I
don't. But I'm guessing it does it more efficiently than looping and
parsing *string* data yourself (and surely you won't argue that VB does not
handle strings all that efficiently).

And where is the result of Split being "thrown away"? It's being used to get
the upper dimension. If you don't want to "throw away" the array it
returns, then assign the array to a variable and use UBound on that variable
(and maybe you can even reuse the variable). Sheesh! It wasn't meant to be
a "thrown-in" example.

Mike

::::::Off-topic and a rant:::::::
This is what I'm talking about Bob! How many times have Rick, Ken, Larry,
etc (IOW, regulars) or anybody else suggested using Split for this EXACT
same purpose? I've never seen you "question" them on it. If you have,
provide a link to the message.



Relevant Pages

  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Byte array to string
    ... Isn't there a faster way than looping through each element of a byte array to ... extract a string? ... Instead of looping though concatenating CHR$) to get the ... string "DaleB" is there a built-in VB function to ...
    (microsoft.public.vb.general.discussion)
  • Re: Adding a NULL to an array then adding array to a data table
    ... string by;'s and put in strTokens ... I'm reading the data from a text file, parsing it out into an array then ... correct format.Couldn't store in highquotaamount Column. ...
    (microsoft.public.dotnet.framework.adonet)
  • Quick 2D array? (VB6)
    ... I have a file I am reading into one long string using Get. ... I want to break this data into a 2D array. ... Is there a quicker way than looping through the string assigning individual ... I can easily SPLIT the string on the CRLF's into a 1D array, ...
    (microsoft.public.vb.bugs)
  • Re: Quick 2D array? (VB6)
    ... I have a file I am reading into one long string using Get. ... I want to break this data into a 2D array. ... Is there a quicker way than looping through the string assigning individual ... I can easily SPLIT the string on the CRLF's into a 1D array, ...
    (microsoft.public.vb.bugs)