Created
November 18, 2013 04:41
-
-
Save supernullset/7522660 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" | |
class KWBM | |
attr_reader :foo, :baz | |
def initialize(foo: "bar", baz: "biz") | |
@foo = foo | |
@baz = baz | |
end | |
def call | |
[foo, baz].join | |
end | |
end | |
class ArgBM | |
attr_reader :foo, :baz | |
def initialize(args={}) | |
@foo = args.fetch(:foo, "bar") | |
@baz = args.fetch(:baz, "biz") | |
end | |
def call | |
[foo, baz].join | |
end | |
end | |
n = 1000000 | |
rep=Benchmark.bm do |x| # !> assigned but unused variable - rep | |
x.report do | |
n.times do | |
KWBM.new.call | |
end | |
end | |
x.report do | |
n.times do | |
ArgBM.new.call | |
end | |
end | |
end | |
# >> user system total real | |
# >> 0.970000 0.000000 0.970000 ( 0.963902) | |
# >> 1.010000 0.000000 1.010000 ( 1.014589) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment