Skip to content

Instantly share code, notes, and snippets.

@rkh
Created August 7, 2011 14:42
Show Gist options
  • Save rkh/1130425 to your computer and use it in GitHub Desktop.
Save rkh/1130425 to your computer and use it in GitHub Desktop.
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)
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