Created
October 4, 2009 04:59
-
-
Save gusgollings/201141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return | |
require 'benchmark' | |
def explicit | |
return 1 | |
end | |
def implicit | |
1 | |
end | |
n = 10_000_000 | |
Benchmark.bmbm do |x| | |
x.report("explicit") { n.times { explicit } } | |
x.report("implicit") { n.times { implicit } } | |
end | |
$ ruby test.rb | |
Rehearsal -------------------------------------------- | |
explicit 4.090000 0.020000 4.110000 ( 4.143585) | |
implicit 2.610000 0.010000 2.620000 ( 2.631262) | |
----------------------------------- total: 6.730000sec | |
user system total real | |
explicit 4.100000 0.010000 4.110000 ( 4.805887) | |
implicit 2.630000 0.010000 2.640000 ( 2.660820) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment