Skip to content

Instantly share code, notes, and snippets.

@chaffeqa
Forked from tarcieri/dci_benchmark.rb
Last active December 10, 2015 05:58
Show Gist options
  • Save chaffeqa/4391160 to your computer and use it in GitHub Desktop.
Save chaffeqa/4391160 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'benchmark/ips'
class ExampleClass
def foo; 42; end
end
module ExampleMixin
def foo; 43; end
end
Benchmark.ips do |bm|
bm.report("without dci") { ExampleClass.new.foo }
bm.report("with extend dci") do
obj = ExampleClass.new
obj.extend(ExampleMixin)
obj.foo
end
bm.report("with include dci") do
obj = ExampleClass.new
obj.include(ExampleMixin)
obj.foo
end
end
# ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
#iterations/sec
without dci 3938758.7 (±1.9%) i/s - 19754280 in 5.017387s
with dci 537904.0 (±8.0%) i/s - 2683515 in 5.024073s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment