public
Created

Which of these is the fastest?

  • Download Gist
set_benchmark.rb
Ruby
1 2 3 4 5 6 7 8 9
x = 10000.times.to_a
 
a,b,c = x.dup, x.dup, x.dup
 
Benchmark.measure { 1000.times { out = []; out += a; out += b; out +=c; out.uniq! } }
 
Benchmark.measure { 1000.times { out = Set.new; out += a; out += b; out +=c; } }
 
Benchmark.measure { 1000.times { out = {}; a.each {|e| out[e] ||= 1}; b.each {|e| out[e] ||= 1}; c.each {|e| out[e] ||= 1}; } }

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.