1. puzzled

Anybody, please, but Rob in particular:

Why is the new 'short circuit' evaluation in the following code
fragment so much slower than its emulation? I get a factor of 3 or 4
on my machines! Is it the 'logical or' that's so expensive? What's
going on?  jiri (puzzledblink

-- snip --------------------------------------------------------------

include machine.e   -- tick_rate

constant
    n=1000000
atom dt,t
integer a,b,c

tick_rate(200)
c=9

-- empty loop
t=time()
for i=1 to n do
end for
dt=time()-t

-- old:
a=0 b=0
t=time()
for i=1 to n do
    if c=32 then a=a+1
    elsif c=9 then a=a+1
    else b=b+1
    end if
end for
t=time()-t-dt
?t

-- new:
a=0 b=0
t=time()
for i=1 to n do
    if c=32 or c=9 then a+=1
    else b+=1
    end if
end for
t=time()-t-dt
?t

new topic     » topic index » view message » categorize

2. Re: puzzled

Your example will not short circuit but even if you change the example so
that it does short circuit (see my changes in your code below), the first
example runs a bit more than twice the speed of the second.  I guess
there's a trade off between less code and longer execution time...

(not that my analysis answered your question...)
-- Brian

On Thu, 9 Sep 1999, Jiri Babor wrote:

> Anybody, please, but Rob in particular:
>
> Why is the new 'short circuit' evaluation in the following code
> fragment so much slower than its emulation? I get a factor of 3 or 4
> on my machines! Is it the 'logical or' that's so expensive? What's
> going on?  jiri (puzzledblink
>
> -- snip --------------------------------------------------------------
>
> include machine.e   -- tick_rate
>
> constant
>     n=1000000
> atom dt,t
> integer a,b,c
>
> tick_rate(200)
> c=9
>
> -- empty loop
> t=time()
> for i=1 to n do
> end for
> dt=time()-t
>
> -- old:
> a=0 b=0
> t=time()
> for i=1 to n do
>     if c=9 then a=a+1     -- was c=32
>     elsif c=32 then a=a+1 -- was c=9
>     else b=b+1
>     end if
> end for
> t=time()-t-dt
> ?t
>
> -- new:
> a=0 b=0
> t=time()
> for i=1 to n do
>     if c=9 or c=32 then a+=1  -- was c=32 or c=9
>     else b+=1
>     end if
> end for
> t=time()-t-dt
> ?t
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: puzzled

Jiri Babor writes:
> Why is the new 'short circuit' evaluation in the following code
> fragment so much slower than its emulation? I get a factor of
> 3 or 4 on my machines! Is it the 'logical or' that's so expensive?
> What's going on?  jiri (puzzledblink

I get a factor of 2.1 on my Pentium-150.

faster:
>    if c=32 then a=a+1
>    elsif c=9 then a=a+1
>    else b=b+1
>    end if

slower:
>    if c=32 or c=9 then a+=1
>    else b+=1
>    end if

A long time ago I carefully optimized the case
of comparing two things that are known (at compile-time)
to be integers, then using the result of the comparison
in an if/elsif/while.

When I did short-circuit evaluation, I opted for
a very safe and simple implementation.
I was afraid of introducing subtle bugs into
people's existing code.

Since no short-circuit bugs have been reported so far,
I guess I could try to be more aggressive in optimizing it.

Regards,
     Rob Craig
     Rapid Deployment Software
     http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

4. Re: puzzled

Sorry, Brian, you are right, bad example. Fortunately it did not make
much difference. Earlier today I noticed that a revamp of my string
functions (trim, etc) runs much slower than the older version. In the
original code, the variable c could, of course, have any char value. I
just picked wrong one...

Rob, I suspected that might be the case. Please fix it. Btw, this sort
of things makes Euphoria an infuriating playing field: goal posts
shifting around all the time. But I guess it also means it is still
alive, developing...

Thanks, guys. jiri

new topic     » goto parent     » topic index » view message » categorize

5. puzzled

What's the point of sending shrouded demos to this list? Jiri

new topic     » goto parent     » topic index » view message » categorize

6. Re: puzzled

BABOR, JIRI wrote:
>
> What's the point of sending shrouded demos to this list? Jiri

1 : i wanted to show some one what i made,
2 : it is not worth putting it on the RDS page,
3 : I accidentaly shrouded OVER my original code so all i have is the
shrouded version,
4 : To my knowledge, no one has died as a direct result of my posting
this program :)

--Augorian;

new topic     » goto parent     » topic index » view message » categorize

7. Re: puzzled

On Wed, 16 Jul 1997, mark honnor wrote:
> 3 : I accidentaly shrouded OVER my original code so all i have is the
> shrouded version,

D'oh!  good to see I'm NOT the only IDIOT around here!

Socrates. <walking away, shaking his head in disgust, laughing
hysterically>


Michael Packard
Lord Generic Productions
lgp at exo.com http://exo.com/~lgp
A Crash Course in Game Design and Production
http://exo.com/~lgp/euphoria

new topic     » goto parent     » topic index » view message » categorize

8. Re: puzzled

The last game ends before anyone wins.

On Wed, 16 Jul 1997 10:07:36 +1200 mark honnor <m.honnor at xtra.co.nz>
writes:
>---------------------- Information from the mail header
>-----------------------
>Sender:       Euphoria Programming for MS-DOS
><EUPHORIA at MIAMIU.ACS.MUOHIO.EDU>
>Poster:       mark honnor <m.honnor at XTRA.CO.NZ>
>Subject:      Re: puzzled
>-------------------------------------------------------------------------------
>
>BABOR, JIRI wrote:
>>
>> What's the point of sending shrouded demos to this list? Jiri
>
>1 : i wanted to show some one what i made,
>2 : it is not worth putting it on the RDS page,
>3 : I accidentaly shrouded OVER my original code so all i have is the
>shrouded version,
>4 : To my knowledge, no one has died as a direct result of my posting
>this program :)
>
>--Augorian;
>

        Jiri is right, I got a decoder, I have version 1.4, your code
doesn't work I want to kill you. BTW what was it supposed to do. Next
time Just send it plain if it is not a zip or such with an indication of
where to "cut". That would make life easier. Thanx

                                Me

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu