Created
December 9, 2013 02:51
-
-
Save keeran/7866740 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
require 'benchmark' | |
def implicit_return | |
arr = (1..1000).to_a | |
arr.inject({}) do |mem, item| | |
mem[item.to_s] = item | |
mem | |
end | |
end | |
def explicit_return | |
arr = (1..1000).to_a | |
hash = arr.inject({}) do |mem, item| | |
mem[item.to_s] = item | |
mem | |
end | |
return hash | |
end | |
puts Benchmark.measure("implicit return test") { | |
1000.times do | |
result = implicit_return | |
end | |
} | |
puts Benchmark.measure("explicit return test") { | |
1000.times do | |
result = explicit_return | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment