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-11.0.2 spike/return_vs_throw.rb
rack-app-11.0.1 spike/return_vs_throw.rb
rack-app-11.0.0 spike/return_vs_throw.rb
rack-app-10.0.0 spike/return_vs_throw.rb
rack-app-9.0.0 spike/return_vs_throw.rb
rack-app-8.1.0 spike/return_vs_throw.rb
rack-app-8.0.1 spike/return_vs_throw.rb
rack-app-8.0.0 spike/return_vs_throw.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/spike/return_vs_throw.rb
rack-app-7.7.0 spike/return_vs_throw.rb
rack-app-7.6.5 spike/return_vs_throw.rb
rack-app-7.6.4 spike/return_vs_throw.rb
rack-app-7.6.3 spike/return_vs_throw.rb
rack-app-7.6.2 spike/return_vs_throw.rb
rack-app-7.6.1 spike/return_vs_throw.rb
rack-app-7.6.0 spike/return_vs_throw.rb
rack-app-7.5.2 spike/return_vs_throw.rb
rack-app-7.5.1 spike/return_vs_throw.rb
rack-app-7.5.0 spike/return_vs_throw.rb
rack-app-7.4.0 spike/return_vs_throw.rb