Created
September 20, 2016 06:58
-
-
Save piotrze/dfc0e91ae0f86670154f4930c99dcce5 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' | |
def normal_param(a, b) | |
return [a, b] | |
end | |
def named_param(a:, b:) | |
return [a, b] | |
end | |
n = 100000 | |
Benchmark.bm(5) do |x| | |
x.report { n.times{ normal_param(1, 2) } } | |
x.report { n.times{ named_param(b: 2, a: 1) } } | |
end | |
# ruby 2.1.5 | |
# user system total real | |
# 0.020000 0.000000 0.020000 ( 0.019686) | |
# 0.140000 0.000000 0.140000 ( 0.141314) | |
# for ruby 2.2.4 | |
# user system total real | |
# 0.020000 0.000000 0.020000 ( 0.023068) | |
# 0.020000 0.000000 0.020000 ( 0.024493) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment