Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tarcieri
Created December 17, 2012 20:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tarcieri/4321750 to your computer and use it in GitHub Desktop.
Save tarcieri/4321750 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 dci") do
obj = ExampleClass.new
obj.extend(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