Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created January 3, 2013 17:26
Show Gist options
  • Select an option

  • Save teeparham/4445137 to your computer and use it in GitHub Desktop.

Select an option

Save teeparham/4445137 to your computer and use it in GitHub Desktop.
Ruby extend performance test
# gem install benchmark-ips
require 'rubygems'
require 'benchmark/ips'
module Mixin
def foo; 42; end
end
class SubclassArray < Array
include Mixin
end
Benchmark.ips do |bm|
bm.report("array") do
Array.new.size
end
bm.report("extend") do
a = Array.new
a.extend Mixin
a.foo
end
bm.report("include") do
a = SubclassArray.new
a.foo
end
end
@teeparham

Copy link
Copy Markdown
Author
ruby bm_extend.rb 
Calculating -------------------------------------
               array     95387 i/100ms
              extend     31050 i/100ms
             include     89500 i/100ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment