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-6.1.0 spike/method_vs_instance_exec.rb
rack-app-6.0.0 spike/method_vs_instance_exec.rb
rack-app-5.12.0 spike/method_vs_instance_exec.rb
rack-app-5.11.1 spike/method_vs_instance_exec.rb
rack-app-5.11.0 spike/method_vs_instance_exec.rb
rack-app-5.10.2 spike/method_vs_instance_exec.rb
rack-app-5.10.1 spike/method_vs_instance_exec.rb
rack-app-5.10.0 spike/method_vs_instance_exec.rb
rack-app-5.9.0 spike/method_vs_instance_exec.rb
rack-app-5.8.0 spike/method_vs_instance_exec.rb
rack-app-5.7.0 spike/method_vs_instance_exec.rb
rack-app-5.7.0.rc spike/method_vs_instance_exec.rb
rack-app-5.6.0 spike/method_vs_instance_exec.rb
rack-app-5.5.1 spike/method_vs_instance_exec.rb
rack-app-5.4.0 spike/method_vs_instance_exec.rb
rack-app-5.3.2 spike/method_vs_instance_exec.rb
rack-app-5.3.1 spike/method_vs_instance_exec.rb
rack-app-5.3.0 spike/method_vs_instance_exec.rb
rack-app-5.2.0 spike/method_vs_instance_exec.rb
rack-app-5.1.0 spike/method_vs_instance_exec.rb