Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ What kind of return values are faster?
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |