Sha256: 6eac76179db389d4dc4855dfca9bc5928ed07bca5fea4ef93e2884aa73c6b56b

Contents?: true

Size: 548 Bytes

Versions: 63

Compression:

Stored size: 548 Bytes

Contents

require 'benchmark'

class TestSubject

  def tvalue
    catch :value do
      tget
    end
  end

  def rvalue
    catch :value do
      rget
    end
  end

  def tget
    throw :value, 'hello'
  end

  def rget
    return 'hello'
  end

end

TEST_AMOUNT = 1_000_000

Benchmark.bm(15) do |x|

  x.report('throw') do
    test_subject = TestSubject.new
    TEST_AMOUNT.times do
      test_subject.tvalue
    end
  end

  x.report('return') do
    test_subject = TestSubject.new
    TEST_AMOUNT.times do
      test_subject.rvalue 
    end
  end

end

Version data entries

63 entries across 63 versions & 2 rubygems

Version Path
rack-app-6.1.0 spike/return_vs_throw.rb
rack-app-6.0.0 spike/return_vs_throw.rb
rack-app-5.12.0 spike/return_vs_throw.rb
rack-app-5.11.1 spike/return_vs_throw.rb
rack-app-5.11.0 spike/return_vs_throw.rb
rack-app-5.10.2 spike/return_vs_throw.rb
rack-app-5.10.1 spike/return_vs_throw.rb
rack-app-5.10.0 spike/return_vs_throw.rb
rack-app-5.9.0 spike/return_vs_throw.rb
rack-app-5.8.0 spike/return_vs_throw.rb
rack-app-5.7.0 spike/return_vs_throw.rb
rack-app-5.7.0.rc spike/return_vs_throw.rb
rack-app-5.6.0 spike/return_vs_throw.rb
rack-app-5.5.1 spike/return_vs_throw.rb
rack-app-5.4.0 spike/return_vs_throw.rb
rack-app-5.3.2 spike/return_vs_throw.rb
rack-app-5.3.1 spike/return_vs_throw.rb
rack-app-5.3.0 spike/return_vs_throw.rb
rack-app-5.2.0 spike/return_vs_throw.rb
rack-app-5.1.0 spike/return_vs_throw.rb