Skip to content

Instantly share code, notes, and snippets.

@ilnurnasyrov2
Created March 1, 2018 14:42
Show Gist options
  • Save ilnurnasyrov2/59b5a77238d2715280304fa145940794 to your computer and use it in GitHub Desktop.
Save ilnurnasyrov2/59b5a77238d2715280304fa145940794 to your computer and use it in GitHub Desktop.
class Aclass
def some_method
end
end
class Bclass < Aclass
end
class Cclass < Bclass
end
class Dclass < Cclass
end
module Amodule
def some_method
end
end
module Bmodule
end
module Cmodule
end
class DclassInheritedFromModules
include Amodule
include Bmodule
include Cmodule
end
require "benchmark"
dmodule = DclassInheritedFromModules.new
dclass = Dclass.new
n = 100_000_000
Benchmark.bm do |x|
x.report "class method lookup" do
n.times { dclass.some_method }
end
x.report "module method lookup" do
n.times { dmodule.some_method }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment