Skip to content

Commit

Permalink
+ What kind of return values are faster?
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiess committed Apr 18, 2012
1 parent 7930d9c commit 61f92c7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions experiments/return_values.rb
@@ -0,0 +1,25 @@
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

n = 1000_000
require 'benchmark'
Benchmark.bmbm(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 }
end

0 comments on commit 61f92c7

Please sign in to comment.