1 more speed question
Jan Schenkel
janschenkel at yahoo.com
Wed May 18 13:50:49 EDT 2005
--- jbv <jbv.silences at Club-Internet.fr> wrote:
> for year we've been told that
> repeat for each line j in myVar
> runs significantly faster than
> repeat for i=1 to number of lines in myVar
>
> that's true, but if you use the following
> repeat with i=1 to number of lines in myVar
> get line i of myVar
>
> and then do all your processing in the "it" variable
> (and then "put it in line i of myVar" at the end of
> the
> repeat loop if necessary), in that case the "repeat
> with i..."
> statement seems to run as fast as "repeat for each
> line..."
>
> does that mean that only the fact that each
> successive line
> is in a variable (and hence has its content easier
> to access
> than in a huge variable with dozens or hundreds of
> lines)
> matters, and that it has nothing to do with the
> repeat
> structure per se ?
>
> Thanks,
> JB
>
Hi JB,
Rest assured that 'repeat for each' is tha fastest
construct by its very nature : the engine knows it's
going through the whole varible, and keeps track of
where it's at, saving it from counting he number of
lines all over again.
However, 'it' is a special variable, and probably
resides in the 'stack' part of the memory rather than
the 'heap' where the engine keeps close tabs on it.
So you would probably get the best performance if you
use something like:
--
repeat for each line tLine in tLongList
get tLine
## now do everything with it
end repeat
--
Jan Schenkel.
Quartam - Tools for Revolution
<http://www.quartam.com>
=====
"As we grow older, we grow both wiser and more foolish at the same time." (La Rochefoucauld)
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
More information about the use-livecode
mailing list