From: hemant Date: 2006-10-22T10:59:25+09:00 Subject: Re: break from block On 10/21/06, ara.t.howard@noaa.gov wrote: > On Sat, 21 Oct 2006, Farrel Lifson wrote: > > > On 20/10/06, Robert Klemme wrote: > >> On 20.10.2006 16:37, Farrel Lifson wrote: > >> > I'm just trying to optimise some code and I was wondering if doing > >> > block = lambda{|i| #processing; if i > 5; break} > >> > n.times &block > >> > would be any faster than doing it directly. > >> > >> I do not know a single case where the lambda variant is faster than the > >> direct block variant. AFAIK that's because of the conversion that > >> occurs. The advantage of the lambda variant is rather that you can > >> store the block away and reuse it multiple times. > >> > >> Regards > >> > >> robert > > > >> From my informal benchmarking there's a very slight constant speedup > > of about 1s for my program. > > what version are you running? your original code works fine here: > > harp:~ > cat a.rb > block = lambda{|i| p i; i > 5 ? break : nil} > 42.times &block > > > harp:~ > ruby a.rb > 0 > 1 > 2 > 3 > 4 > 5 > 6 > > harp:~ > ruby --version > ruby 1.8.4 (2005-12-01) [i686-linux] > > harp:~ > uname -srm > Linux 2.4.21-47.EL i686 > > harp:~ > cat /etc/redhat-release > Red Hat Enterprise Linux WS release 3 (Taroon Update 8) > > can you show an actual error? This is wierd , i got the same error here: uname -a Linux webfront 2.6.15-23-server #1 SMP Tue May 23 15:10:35 UTC 2006 i686 GNU/Linux ruby -v ruby 1.8.4 (2005-12-24) [i486-linux] Dapper How, come you are not getting the error? -- There was only one Road; that it was like a great river: its springs were at every doorstep, and every path was its tributary.