Created
November 26, 2014 02:04
-
-
Save subvertallchris/bd86953c9ef696370999 to your computer and use it in GitHub Desktop.
Testing implicit VS explicit returns
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
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.config(warmup: 1, time: 5) | |
def test1 | |
a = [:foo, :bar, :baz, :omg, :wtf, :gtfo] | |
a.map(&:to_s) | |
end | |
def test2 | |
return [:foo, :bar, :baz, :omg, :wtf, :gtfo].map(&:to_s) | |
end | |
x.report('implicit return') do | |
test1 | |
end | |
x.report('explicit return') do | |
test2 | |
end | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment