S = Set.new.compare_by_identity.freeze
H = Hash.new.compare_by_identity.freeze
Benchmark.ips do |x|
x.config(time: 10)
x.report(".new.compare_by_identity") do |times|
i = 0
while (i += 1) <= times
S.dup
end
end
x.report(".dup ") do |times|
i = 0
while (i += 1) <= times
Set.new.compare_by_identity
end
end
x.compare!
end
Benchmark.ips do |x|
x.config(time: 10)
x.report(".new.compare_by_identity") do |times|
i = 0
while (i += 1) <= times
H.dup
end
end
x.report(".dup ") do |times|
i = 0
while (i += 1) <= times
Hash.new.compare_by_identity
end
end
x.compare!
end
It's one less allocation, too :)
Set.new.compare_by_identity
S.dup
Hash.new.compare_by_identity
H.dup