Sha256: 6949bb8253e38beeb3d20c33b0f3b0ecd7bbd1e06b3c73b30effba44c0ba28d6

Contents?: true

Size: 621 Bytes

Versions: 4

Compression:

Stored size: 621 Bytes

Contents

require "benchmark/ips"
require "binding_ninja"
require "binding_of_caller"

class Foo
  extend BindingNinja

  auto_inject_binding def foo1(b)
    b.local_variables
  end

  def foo2
    binding.of_caller(1).local_variables
  end

  def foo3(b)
    b.local_variables
  end
  auto_inject_binding :foo3, if: :enable_auto_inject_binding?

  def enable_auto_inject_binding?
    true
  end
end

foo = Foo.new

p foo.foo1
p foo.foo2
p foo.foo3

Benchmark.ips do |x|
  x.report("binding_ninja") { foo.foo1 }
  x.report("binding_ninja_with_condition") { foo.foo3 }
  x.report("binding_of_caller") { foo.foo2 }

  x.compare!
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
binding_ninja-0.2.3 benchmark.rb
binding_ninja-0.2.3-java benchmark.rb
binding_ninja-0.2.2 benchmark.rb
binding_ninja-0.2.1 benchmark.rb