Last active
December 26, 2015 13:39
-
-
Save ihower/7160400 to your computer and use it in GitHub Desktop.
Revisions
-
ihower revised this gist
Oct 25, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ def hello end end class MixinPerson include Greeter end @@ -53,7 +53,7 @@ def hello person0.hello }} x.report("mixin") { n.times { person1 = MixinPerson.new person1.hello }} x.report("my wrapper") { n.times { -
ihower created this gist
Oct 25, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ require 'casting' require 'benchmark' require 'delegate' module Greeter def hello %{hello from #{self}} end end class Person end class InheritedPerson < Person def hello %{hello from #{self}} end end class FastPerson include Greeter end class CastingPerson include Casting::Client end class CastingAllPerson include Casting::Client delegate_missing_methods end class DelegatorPerson < SimpleDelegator def hello %{hello from #{self}} end end class WrapperPerson def initialize(person) @person = person end def hello %{hello from #{@person}} end end n = 100000 Benchmark.bm do |x| x.report("inherited") { n.times { person0 = InheritedPerson.new person0.hello }} x.report("mixin") { n.times { person1 = FastPerson.new person1.hello }} x.report("my wrapper") { n.times { person2 = WrapperPerson.new(Person.new) person2.hello }} x.report("simple delegator") { n.times { person3 = DelegatorPerson.new(Person.new) person3.hello }} x.report("dynamic extend") { n.times { person4 = Person.new person4.extend(Greeter) person4.hello }} #x.report("casting") { n.times { # CastingPerson.new.delegate(:hello, Greeter) #}} #x.report("casting all") { n.times { # person6 = CastingAllPerson.new # person6.cast_as(Greeter) # person6.hello #}} end