Intersecting data question/challenge

Raymond E. Griffith rgriffit at ctc.net
Fri Jul 8 20:26:15 EDT 2005


Dennis,

I have a suggestion. It isn't perfect, but it does appear to be relatively
fast.

I start by creating return-delimited lists. The lists have 5000 elements in
them and 2000 elements in them, respectively, although due to repeats the
customkeys are significantly less.

One problem is that you cannot set the keys of a variable directly. You can,
however, set the customkeys of an object directly, then put those
customproperties into a variable.

Then use intersect.

As I said, this appears to me to be relatively fast.

on mouseUp
  put 5000 into n1
  put 2000 into n2
  repeat with i = 1 to n1
    put random(10000) & cr after A
  end repeat
  repeat with i = 1 to n2
    put random(10000) & cr after B
  end repeat
  put the long milliseconds into ms
  set the customkeys of fld "LA" to A
  set the customkeys of fld "LB" to B
  put the customproperties of fld "LA" into arrA
  put the customproperties of fld "LB" into arrB
  intersect arrA with arrB
  answer keys(arrA) & return & "___" & the long milliseconds - ms
end mouseUp

Perhaps someone can try comparing this idea with others for time trials?

I hope this helps.

Raymond E. Griffith


> JB,
> 
> You are right in that if I already had the lists setup as keys in an
> array it could run faster.  In that case your example below with a
> repeat loop runs about the same speed as my original example with a
> repeat loop.  However, using the intersect command instead of a
> repeat loop would run 4-8 times as fast as either loop version and is
> fast enough to use for my intended purpose as a direct test to see
> which blocks of code to execute inside a large loop.
> 
> Unfortunately, an array is not an easy thing to use as a constant to
> check against.  I would have to pre-build all my arrays beforehand.
> If I have to do that, I might just as well build an execution test
> matrix using the simple lists as parameters.  I just wanted to avoid
> one more level of indirection for the sake of speed (I have so many
> already).  However, I think I understand some new tricks now with
> your help and from Eric, Alex, and Chris.
> 
> Thanks,
> Dennis
> 
> On Jul 8, 2005, at 4:27 PM, jbv wrote:
> 
>> 
>> 
>> Dennis,
>> 
>> Using arrays will always be a speed improvement.
>> 
>> My script creates arrays from your lists of items with loops
>> just for the purpose of the demonstration. As someone else
>> suggested, you can use "split" to create your arrays, or better :
>> drop your lists of items and configure your data as arrays
>> from the beginning.
>> 
>> Just for the anecdote, I have a cgi script that makes extensive
>> use of arrays (and only arrays), and it builds 16 pages pdf
>> files of about 1.4 Mb in roughly 0.1 second, while the previous
>> version (using items lists) took 3 to 4 seconds...
>> 
>> JB
>> 
>> 
>>> JB,
>>> 
>>> It will work, but not a speed improvement.
>>> It will run about 8 times slower than my original example.
>>> It takes Rev a lot of work (time) to create an array element.
>>> 
>>> Dennis
>>> 
>>> On Jul 8, 2005, at 2:50 PM, jbv wrote:
>>> 
>>> 
>>>> 
>>>> 
>>>> Dennis,
>>>> 
>>>> Use arrays; Something like :
>>>> 
>>>> put "" into myT1
>>>> put "" into myT2
>>>> repeat for each item i in list1
>>>>     put 1 into myT1[i]
>>>> end repeat
>>>> repeat for each item i in list2
>>>>     put 1 into myT2[i]
>>>> end repeat
>>>> 
>>>> get the keys of myT1
>>>> repeat for each line j in it
>>>>     if myT2[j]=1 then
>>>>         get true
>>>>         exit repeat
>>>>     end if
>>>> end repeat
>>>> 
>>>> JB
>>>> 
>>>> 
>>>> 
>>>>> Hello clever Rev programmers,
>>>>> 
>>>>> I have a simple question or maybe it is a simple challenge.
>>>>> 
>>>>> I have two lists of integers.  The list are not long, perhaps 5
>>>>> to 50
>>>>> items e.g.:
>>>>> list1="310,423,522,211,107,340,"
>>>>> lis2="311,312,313,318,320,323,325,330,333,337,340,"
>>>>> 
>>>>> I want to find if any of the items in list1 have a match in list2.
>>>>> I know I could do it with a repeat, something like this:
>>>>> 
>>>>> get false
>>>>> repeat for each item theItem in list1
>>>>>    if theItem is not among the items of list2 then next repeat
>>>>>    get true
>>>>>    exit repeat
>>>>> end repeat
>>>>> 
>>>>> I was wondering if it could be done faster without a repeat through
>>>>> some Rev trick.
>>>>> 
>>>>> Dennis
>>>>> _______________________________________________
>>>>> use-revolution mailing list
>>>>> use-revolution at lists.runrev.com
>>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>>> subscription preferences:
>>>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>>> 
>>>>> 
>>>> 
>>>> _______________________________________________
>>>> use-revolution mailing list
>>>> use-revolution at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>> 
>>>> 
>>> 
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>> 
>> 
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list