From: David Vallner Date: 2006-01-11T14:36:39+09:00 Subject: Re: use of "return" Ryan Leavengood wrote: >On 1/10/06, Jim Freeze wrote: > > >>Seems like every time I check, code with a 'return' runs slower >>than code without. Less typing and faster. I say drop the return. >> >> > >Confirmed: > >require 'quickbench' > >class Test > def initialize(test) > @test = test > end > > def test > @test > end > > def get_test > return @test > end >end > >t = Test.new("something") >QuickBench.go(3000000, 25) {} > >__END__ >t.test >t.get_test > >Results: > >------------------------------------------------------------------------- >| QuickBench Session Started | >| 3000000 Iterations | >------------------------------------------------------------------------- > user system total real >1. t.test 2.860000 0.000000 2.860000 ( 2.859000) >2. t.get_test 3.078000 0.000000 3.078000 ( 3.094000) >------------------------------------------------------------------------- >| Fastest was <1. t.test> | >------------------------------------------------------------------------- > >Ryan > > > Most weird. Let's hope someone notices and the compiler is modified to plain drop tail-returns. That is, if "return" is a reserved word and thus not viable to being overridden by someone who codes with a dead chicken in his left hand ;P (Gotta love it when flexibility bites you back. *daydreams about clean blocks*)