Created
          August 7, 2011 14:42 
        
      - 
      
- 
        Save rkh/1130425 to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | Rehearsal ----------------------------------------------- | |
| instan_eval 0.258967 0.019441 0.278408 ( 0.485533) | |
| bind.call 0.078391 0.003822 0.082213 ( 0.124251) | |
| -------------------------------------- total: 0.360621sec | |
| user system total real | |
| instan_eval 0.259275 0.004492 0.263767 ( 0.309966) | |
| bind.call 0.042689 0.000107 0.042796 ( 0.043009) | 
  
    
      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
    
  
  
    
  | require 'benchmark' | |
| class DSL | |
| def add(x) x + 10 end | |
| end | |
| num, value, block = 50000, 20, proc { add value } | |
| DSL.send(:define_method, :bind_me, &block) | |
| undbound_method = DSL.instance_method(:bind_me) | |
| DSL.send(:remove_method, :bind_me) | |
| Benchmark.bmbm do |x| | |
| x.report("instan_eval") { num.times { DSL.new.instance_eval(&block) }} | |
| x.report("bind.call") { num.times { undbound_method.bind(DSL.new).call }} | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment