Created
February 7, 2011 23:48
-
-
Save mlomnicki/815546 to your computer and use it in GitHub Desktop.
include_vs_extend
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
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