Created
February 5, 2015 17:51
-
-
Save sgrif/b86832786551aaee74de to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def baz(x) | |
x + yield | |
end | |
def bar(&block) | |
baz(1, &block) | |
end | |
def foo(&block) | |
bar(&block) | |
end | |
def foo_with_manual_delegation | |
bar_with_manual_delegation { yield if block_given? } | |
end | |
def bar_with_manual_delegation | |
baz(1) { yield if block_given? } | |
end | |
require "benchmark/ips" | |
Benchmark.ips do |bm| | |
bm.report("&block") { foo { 1 } } | |
bm.report("manual") { foo_with_manual_delegation { 1 } } | |
bm.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment