Skip to content

Instantly share code, notes, and snippets.

@mlomnicki
Created February 7, 2011 23:48
Show Gist options
  • Save mlomnicki/815546 to your computer and use it in GitHub Desktop.
Save mlomnicki/815546 to your computer and use it in GitHub Desktop.
include_vs_extend
module Foo
def bar
end
def baz
end
end
module Baz
def foo
end
def bar
end
end
module Caz
100.times do |i|
define_method "meth_#{i}" do
a = 1
end
end
end
class User
include Foo
include Baz
include Caz
end
class BlankUser
end
u = User.new
bu = BlankUser.new
require 'benchmark'
n = 1_000_000;
Benchmark.bmbm do |x|
x.report("include") { n.times { u.bar } }
x.report("extend") { bu.extend(Foo); n.times { bu.bar } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment