Repeats repeated

David Vaughan dvk at dvkconsult.com.au
Sun Nov 3 02:35:01 EST 2002


On Sunday, Nov 3, 2002, at 17:13 Australia/Sydney, Terry Vogelaar wrote:

> Hi all,
>
snip

> So I tried the same technique with another script that has a triple 
> repeat loop. The var "t" contains about 150 short lines and the script 
> is intended to put every possible combination of 3 lines of t into a 
> field:
>
>   repeat with f1 = 1 to the number of lines of t - 2
>     put line f1 of t into g1
>     repeat with f2 = f1+1 to the number of lines of t - 1
>       put line f2 of t into g2
>       repeat with f3 = f2+1 to the number of lines of t
>        put line f3 of t into g3
>        put g1&","&g2&","&g3& return after fld "uitvoer"
>       end repeat
>     end repeat
>   end repeat
>
> That took 101 seconds. So I tried to speed it up with what I learned 
> about "repeat for each":
>
>   put line 1 to -3 of t into t1
>   put 0 into f1
>   repeat for each line g1 in t1
>     add 1 to f1
>     put line f1+1 to -2 of t into t2
>     put 0 into f2
>     repeat for each line g2 in t2
>       add 1 to f2
>       put line f2+1 to -1 of t into t3
>       repeat for each line g3 in t3
>         put g1&","&g2&","&g3& return after fld "uitvoer"
>       end repeat
>     end repeat
>   end repeat
>
> 364 seconds! And I thought it would be faster!  It involved some extra 
> vars, but since it is not much data processed, I don't think memory 
> issues could explain this.
>
> Any thoughts why this is much slower than the original script and how 
> I can speed this up?

Terry

I can see why repeat for each failed here - you need to extract subsets 
of the main list for each of the inner RFE loops for each time through 
its outer loop. Thus, you are extracting by line numbers and doing more 
work than in the first instance. RFE is fast through each sub-list but 
the work of continually creating new lists is an overwhelming burden. 
Not sure how to solve it using arrays as you seem to wind up with the 
same problem only this time fiddling with keys. Since Richard suggested 
that approach, perhaps he has something in mind.....

regards
David
>
> Terry
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list