Skip to content

Instantly share code, notes, and snippets.

@kirikak2
Last active September 20, 2017 01:04
Show Gist options
  • Save kirikak2/7ff0aa7fcb166aecb35fcce3b0778f94 to your computer and use it in GitHub Desktop.
Save kirikak2/7ff0aa7fcb166aecb35fcce3b0778f94 to your computer and use it in GitHub Desktop.
require "benchmark"
require "binding_ninja"
require "binding_of_caller"
class Ninja
extend BindingNinja
def initialize(binding)
binding.eval("@hoge")
end
auto_inject_binding :initialize
end
class OfCaller
def initialize()
binding.of_caller(1).eval("@hoge")
end
end
@hoge = 1
Benchmark.bm do |x|
x.report("binding_ninja:"){ 100000.times{ Ninja.new } }
x.report("binding_of_caller:"){ 100000.times{ OfCaller.new } }
end
user     system      total        real
binding_ninja:  0.350000   0.000000   0.350000 (  0.356695)
binding_of_caller:  2.140000   0.000000   2.140000 (  2.139886)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment