Repeats repeated
Richard Gaskin
ambassador at fourthworld.com
Sun Nov 3 01:56:01 EST 2002
Terry Vogelaar wrote:
> Last week I asked a question about filtering the double lines in a var
> with many lines. The list helped very well by pointing out that I
> shouldn't use "repeat with", but "repeat for each", which brought the
> processing time back from 60 hours to 4 seconds (!)
>
> 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?
Every time you count a line number it eats time. Arrays are faster for this
-- check out the split and combine commands to see how to convert chunks to
arrays andback again.
Also, take anything that touches a field out of the loop for an even greater
speed increase.
--
Richard Gaskin
Fourth World Media Corporation
Custom Software and Web Development for All Major Platforms
Developer of WebMerge 2.0: Publish any database on any site
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
Tel: 323-225-3717 AIM: FourthWorldInc
More information about the use-livecode
mailing list