Skip to content

Instantly share code, notes, and snippets.

@supernullset
Created November 18, 2013 04:41
Show Gist options
  • Save supernullset/7522660 to your computer and use it in GitHub Desktop.
Save supernullset/7522660 to your computer and use it in GitHub Desktop.
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