Created
January 3, 2013 17:26
-
-
Save teeparham/4445137 to your computer and use it in GitHub Desktop.
Ruby extend performance test
This file contains hidden or 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
| # 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
commented
Jan 3, 2013
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment