On 1/10/06, Jim Freeze <jim / freeze.org> 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