Re: Faster way?
- Posted by Lucius Hilley <l3euphoria at bellsouth.net> Dec 26, 2002
- 452 views
Yeah, but what about the inner loop? It calculates length() every time the outer runs. Perfect 2D sequences is going to have all same inner lengths. Why bother checking size of each inner if they are all the same. Lucius L. Hilley III ----- Original Message ----- From: "Robert Elia" <bobelia200 at netzero.net> To: "EUforum" <EUforum at topica.com> Subject: RE: Faster way? At 02:32 25.12.02 +0000, you wrote: > > >dubetyrant at hotmail.com wrote: > > Hello, > > I'm wondering if there is a more efficient(meaning faster) way of > > comparing each element of a sequence with each element of another > > sequence of the same size.Im matching an image with a background > > image,and <snip> >also you are using the 'length' function in your loop control statement. >each time this statement is executed so would the length function be >re-calculated. >calculate it once prior to entering the loop would help. > >seqsize = length(image) >for i = 1 to seqsize by 1 do >if image[i] = 255 then >image[i] = background[i] >end if >end for > >Merry Christmas and Happy New Year to All Euphorians >Rudy >lotterywars Actually, this is only true for while loops. for loops use the length() function only once. Here's a demo: --------------------------- sequence s puts(1, "for loop:for i = 1 to length(s) do --accesses length(s) only once\n") s={1,2,3,4,5} ? s for i = 1 to length(s) do --accesses length(s) only once printf(1, "%2d ", {length(s)}) ? s s = s & i end for puts(1, "while length(s) > 2 do --accesses length(s) on each iteration\n") ? s while length(s) > 2 do --accesses length(s) on each iteration printf(1, "%2d ", {length(s)}) ? s s = s[2..length(s)] end while I think Rob commented on this a while back. Bob ==^^=============================================================== This email was sent to: l3euphoria at bellsouth.net ---------------------------------------------------------------------------- ---- > > --- >