Skip to content

Instantly share code, notes, and snippets.

@subvertallchris
Created November 26, 2014 02:04
Show Gist options
  • Select an option

  • Save subvertallchris/bd86953c9ef696370999 to your computer and use it in GitHub Desktop.

Select an option

Save subvertallchris/bd86953c9ef696370999 to your computer and use it in GitHub Desktop.
Testing implicit VS explicit returns
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