File: return_values.rb

package info (click to toggle)
ruby-parslet 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,260 kB
  • sloc: ruby: 6,157; sh: 8; javascript: 3; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def pair
  [true, "123"]
end

Success = Struct.new(:value)
def struct
  Success.new("123")
end

class SuccessO
  def initialize(value)
    @value = value
  end
end
def klass
  SuccessO.new("123")
end

def raise_ex
  fail "123"
end


n = 1000_00
require 'benchmark'
Benchmark.bm(9) do |bm|
  bm.report(:pair)    { n.times do pair end }
  bm.report(:struct)  { n.times do struct end }
  bm.report(:klass)  { n.times do klass end }
  bm.report(:throw)  { n.times do raise_ex rescue nil end }
end