Skip to content

Instantly share code, notes, and snippets.

@chrisseaton
Created December 18, 2018 13:56
Show Gist options
  • Save chrisseaton/a80f66318873bf9e106eaa2dedbd0814 to your computer and use it in GitHub Desktop.
Save chrisseaton/a80f66318873bf9e106eaa2dedbd0814 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
module Foo
extend self
def foo(a, b, c)
hash = {a: a, b: b, c: c}
array = hash.map { |k, v| v }
x = array[0]
y = [a, b, c].sort[1]
x + y
end
end
class Bar
def method_missing(method, *args)
if Foo.respond_to?(method)
Foo.send(method, *args)
else
0
end
end
end
bar = Bar.new
Benchmark.ips do |x|
x.iterations = 3
x.report 'metaprogramming' do
bar.foo(14, 8, 6)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment