RE: Fastest Selection



User entry is all up front and may come from a data file..
I tried these two methods.

Method 1
create two arrays.
loop through the key array and build a field of max length,
Then Lset each key into it own element and join into a long string
Then later at max program speed, use instr to locate the key.
Calculate the index of the item based on the fixed length of each element.
Use that index into the items to get the value.
Can be used with text or numeric items.

Method II
Just loop through the arrays until a match is found and use the key's index
to get the item at same index.

Results
Both are very fast but the Instr method typically is 20% faster.
After many runs of large loops (10,000) doing a search using both methods it
was unteresting to see that the speed and % difference varied all over the
place probably based on what Windows was up to at the time.

"Lorin" wrote:

I need to rapidly get a token from a string list.
e.g.
Dim sStr as String
Dim sToken as String

sStr = "Orange,Apple,Banna,Pear" ' this is a stub since the list can be
quite long.
sToken = "22,99,44,33" ' matching number of items in each

Both of these are user inputs so I do not immediately control the length of
each item.

Once set, these will not change for the app run.

If the user select Apple then token 99 should be returned.
If Orange, Apple were all the same length then I could get an index from an
Instr calculation, but they can be most any length.
Seems there must be something faster than a For Next loop of items set in
an array.
yes, VB6
suggestions please

.



Relevant Pages

  • Re: Parsing between a character and sysmbol
    ... I did say was that your statement of avoiding arrays inside loops whenever ... creating new String objects. ... This is what I got inside its main loop (I'm not ... the "-" char into an array of chars. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Whats the best language to learn...
    ... over the arrays of vertices, ... loop over the selected models; ... recently my edge construction and shadow-volume rendering code ... but enums just make it easier and quicker to make ...
    (comp.programming)
  • Re: GNAT compiler switches and optimization
    ... allocating and freeing arrays, the the effects ... But I imagined allocation is just what is happening all the time ... type LIST is array of BOOLEAN; ... 2000 loop ...
    (comp.lang.ada)
  • Re: Non-rectangular 3D plot
    ... Ok I see where my code would get very confusing now. ... I originally had it accepting arrays for my inputs, ... I have shown my new code below without x and y in the for loop. ... to have y increment over a counter j for a given x value. ...
    (comp.soft-sys.matlab)
  • HHow can we Speed Up This Wend/While Loop
    ... I need some assistance to speed up a while / wend loop which I have ... The purpose of the loop is to populate two single dimension ... The recordset is made up of two columns, ... The two arrays on the other hand are called strLabel and curData, ...
    (comp.lang.basic.visual.misc)

Loading