fastes way to search an array?

Geoff Canyon gcanyon at gmail.com
Wed Apr 22 11:09:11 EDT 2015


One way to do this would be combine the array (or maintain a duplicate
copy) and use the filter command to do the search.

On Wed, Apr 22, 2015 at 8:44 AM, Rick Harrison <harrison at all-auctions.com>
wrote:

> Hi Tiemo,
>
> What is the average and worst time that it takes to search your 20,000
> record array now?
> Are there users other than you involved? Is it worth the time it will take
> you to optimize
> the code for the faster execution?
>
> Now that you’ve hopefully answered these questions for yourself, and
> decided
> it’s worth the effort, let’s more things forward a little more.
>
> Is your array pre-sorted alphabetically? (Assuming you are aiming for that
> order.)
> If so, it might make sense to split your big array into smaller
> alphabetically sorted
> arrays.  Then you can test for which array to search based on the first
> letter of the
> element you are searching for in the array, and search the smaller array.
>
> Do a few timed tests with your array search so you can measure how much of
> an improvement you have achieved.
>
> Good luck!
>
> Rick
>
>
>
> > On Apr 22, 2015, at 9:20 AM, Tiemo Hollmann TB <toolbook at kestner.de>
> wrote:
> >
> > Hello,
> >
> > I have an array with 20000 records, where I want to extract all records,
> > which either "begins with" or "contains" a search string.
> >
> > Up to now I just loop thru the whole array, do the compare and extract
> the
> > result records. I wonder, if there is a way to speed up this search?
> E.g.,
> > does it makes a difference, if I compare the string in the key or the
> data
> > of the array while looping thru? I mean, would it make a difference, if I
> > would create an "associative" array, where my search looks up in the
> keys of
> > the array, either by looping thru the array, or by extracting first the
> keys
> > of the array into a separate variable, instead in the data of the
> original
> > array?
> >
> > Would it make a difference looping thru a variable, which just contains
> the
> > keys of the array, instead of looping thru the complete array, because of
> > the smaller "footprint" in the memory?
> >
> > Or shouldn't I care about these differences and just let LC makes its
> job?
> >
> > Any experiences welcome,
> >
> > Tiemo
> >
> >
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the Use-livecode mailing list