Created
December 24, 2013 15:00
-
-
Save tobi/8114443 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 regular(a, b, c) | |
[a, b, c] | |
end | |
def keyword(a: 1, b: 2, c: 3) | |
[a, b, c] | |
end | |
def hash(a) | |
[a[:a], a[:b], a[:c]] | |
end | |
number = 1000000 | |
Benchmark.bm(4) do |bm| | |
bm.report("regular") { number.times { regular(4, 5, 6) } } | |
bm.report("keyword") { number.times { keyword(a: 4, b: 5, c: 6) } } | |
bm.report("hash") { number.times { hash(:a => 4, :b => 5, :c => 6) } } | |
end |
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
tobi@box ~/tmp » ruby bm.rb | |
user system total real | |
regular 0.170000 0.000000 0.170000 ( 0.176344) | |
keyword 1.680000 0.010000 1.690000 ( 1.677325) | |
hash 0.790000 0.000000 0.790000 ( 0.794840) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment