Speed
David Vaughan
dvk at dvkconsult.com.au
Wed Sep 18 05:31:01 EDT 2002
On Wednesday, Sep 18, 2002, at 20:08 Australia/Sydney, Jim Hurley wrote:
> This is a postscript to my previous message regarding speed.
>
> I'm embarrassed to say there is a simple way to employ "repeat for
> each line..." and the difference in speed is profound.
>
> But I would nevertheless like to understand why "repeat with i = 1 to
> the number of lines in...." is so much slower
Jim
It is the counting, which is done each time. Imagine you have a list of
a paltry three lines. The linefeed character marks the end of line, and
you have no other information. So, to get line 1, you count up
character by character from 1 to the first linefeed. For line 2, start
at char 1 again and count until the second linefeed, taking data from
the first one. For line 3, count from the beginning again... you can
see this gets pretty tedious, even for a computer, when you are
referencing lines 5997, 5998 and so on.
Worse, if within the loop you refer to that line by index again, then
it is counted again. After all, you may have changed the data in the
meantime.
> and whether putting the list of lines in an array is the better way
> to go in those situations where "repeat for each...." is not > practical.
Using an array is faster than doing the line index thing. Look up
combine and split to convert between arrays and existing lists, or
create new arrays on the fly.
Have fun.
cheers
David
>
> _______________________________________________
> 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