Re: loops & perfomace

new topic     » goto parent     » topic index » view thread      » older message » newer message

I don't think it makes a difference.  Euphoria would appear to be executing 
the for loop the 'smart' way.  I did a quick test with this code--

sequence s
s=repeat(32,50000000)
atom a,t0,loop_overhead
integer lengthofs

t0=time()
lengthofs=length(s)
for c=1 to lengthofs do
    a=power(2,20)
end for
loop_overhead=time()-t0
puts(1,sprintf("%d seconds",loop_overhead))

...and then tried it, replacing this line:
for c=1 to lengthofs do
with this one:
for c=1 to length(s) do

and it ran at the same speed.

This code was just lifted from the docs located in 
C:\EUPHORIA\HTML\LIB_S_T.HTM, and slightly modified...

--Ted

--On Saturday, April 28, 2001 12:01 PM +0200 martin.stachon at worldonline.cz 
wrote:

>
>
>
> Need a better decision-making tool to research, evaluate and
> select software for enterprise applications or manufacturing
> point solutions? Masg.com is where you'll find help.
>
>
> Hi,
> i've got an performace question. We've got a loop
>
> for i=1 to length(s) do
>        ...
> end for
>
> is length(s) evaluated every time loop is done? So would be in Euphoria
> faster
>
> l= length(s)
> for i=1 to l do
>     ...
> end for
>
> as i read in one C book?
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu