Sha256: 5884a15354ae0dcbf03adb8e2a3da2e92e488e75c6f20648e82d41a4c0020904

Contents?: true

Size: 514 Bytes

Versions: 63

Compression:

Stored size: 514 Bytes

Contents

require 'benchmark'

class TestSubject
  def test
    'OK'
  end
end

block = proc do
  test
end

TestSubject.__send__(:define_method, :defined_method,&block)

TEST_AMOUNT = 1_000_000

Benchmark.bm(15) do |x|

  x.report('method call') do
    TEST_AMOUNT.times do
      test_subject = TestSubject.new
      test_subject.__send__(:defined_method)
    end
  end

  x.report('instance_exec') do
    TEST_AMOUNT.times do
      test_subject = TestSubject.new
      test_subject.instance_exec(&block)
    end
  end

end

Version data entries

63 entries across 63 versions & 2 rubygems

Version Path
rack-app-11.0.2 spike/method_vs_instance_exec.rb
rack-app-11.0.1 spike/method_vs_instance_exec.rb
rack-app-11.0.0 spike/method_vs_instance_exec.rb
rack-app-10.0.0 spike/method_vs_instance_exec.rb
rack-app-9.0.0 spike/method_vs_instance_exec.rb
rack-app-8.1.0 spike/method_vs_instance_exec.rb
rack-app-8.0.1 spike/method_vs_instance_exec.rb
rack-app-8.0.0 spike/method_vs_instance_exec.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/spike/method_vs_instance_exec.rb
rack-app-7.7.0 spike/method_vs_instance_exec.rb
rack-app-7.6.5 spike/method_vs_instance_exec.rb
rack-app-7.6.4 spike/method_vs_instance_exec.rb
rack-app-7.6.3 spike/method_vs_instance_exec.rb
rack-app-7.6.2 spike/method_vs_instance_exec.rb
rack-app-7.6.1 spike/method_vs_instance_exec.rb
rack-app-7.6.0 spike/method_vs_instance_exec.rb
rack-app-7.5.2 spike/method_vs_instance_exec.rb
rack-app-7.5.1 spike/method_vs_instance_exec.rb
rack-app-7.5.0 spike/method_vs_instance_exec.rb
rack-app-7.4.0 spike/method_vs_instance_exec.rb