Created
August 30, 2012 16:32
-
-
Save banker/3532481 to your computer and use it in GitHub Desktop.
Which of these is the fastest?
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
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