Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@banker
Created August 30, 2012 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save banker/3532481 to your computer and use it in GitHub Desktop.
Save banker/3532481 to your computer and use it in GitHub Desktop.
Which of these is the fastest?
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}; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment