Created
April 1, 2016 20:38
-
-
Save Overbryd/79dd9f187edd220e9927159172d8243a to your computer and use it in GitHub Desktop.
Ruby named params benchmark
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
require "benchmark/ips" | |
# Run instructions | |
# | |
# gem install benchmark-ips | |
# ruby benchmark.rb | |
def with_named_params(a:, b:) | |
a + b | |
end | |
def without_named_params(a, b) | |
a + b | |
end | |
def without_named_params_hash(h) | |
h[:a] + h[:b] | |
end | |
Benchmark.ips do |x| | |
x.report("named") do | |
with_named_params(a: 1, b: 2) | |
end | |
x.report("arguments") do | |
without_named_params(1, 2) | |
end | |
x.report("hash") do | |
without_named_params_hash(a: 1, b: 2) | |
end | |
x.compare! | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run on a MacBookPro11,5 Intel Core i7 2,5 GHz