Skip to content

Instantly share code, notes, and snippets.

@botanicus
Forked from carllerche/gist:177377
Created August 29, 2009 09:38
Show Gist options
  • Save botanicus/177437 to your computer and use it in GitHub Desktop.
Save botanicus/177437 to your computer and use it in GitHub Desktop.
require "rubygems"
require "rbench"
def omg_slow
return 1
end
def omg_fast
1
end
RBench.run(10_000_000) do
column :one, :title => "Using return"
column :two, :title => "Avoiding return"
report "Returning from methods" do
one { omg_slow }
two { omg_fast }
end
end
__END__
ruby1.8 gistfile1.rb
Using return | Avoiding return |
---------------------------------------------------------------
Returning from methods 4.784 | 3.050 |
ruby1.9 gistfile1.rb
Using return | Avoiding return |
---------------------------------------------------------------
Returning from methods 2.278 | 2.228 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment