Re: puzzled
- Posted by "Brian K. Broker" <bkb at CNW.COM> Sep 08, 1999
- 505 views
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 (puzzled > > -- 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 >