Created
December 18, 2018 13:56
-
-
Save chrisseaton/a80f66318873bf9e106eaa2dedbd0814 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/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