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)
Last active
September 20, 2017 01:04
-
-
Save kirikak2/7ff0aa7fcb166aecb35fcce3b0778f94 to your computer and use it in GitHub Desktop.
This file contains 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" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment