title: What is the fastest way to make a uniq array?
body: <p>I've got the following situation. I have got a big array of random strings. This array should be made unique as fast as possible.</p>
  
  <p>Now through some Benchmarking I found out that ruby's uniq is quite slow:</p>
  
  <pre><code>require 'digest'
  require 'benchmark'
  
  #make a nice random array of strings
  list = (1..100000).to_a.map(&amp;:to_s).map {|e| Digest::SHA256.hexdigest(e)}
  list += list
  list.shuffle
  
  def hash_uniq(a)
    a_hash = {}
    a.each do |v|
      a_hash[v] = nil
    end
    a_hash.keys
  end
  
  Benchmark.bm do |x|
    x.report(:uniq) { 100.times { list.uniq} }
    x.report(:hash_uniq) { 100.times { hash_uniq(list) } }
  end
  </code></pre>
  
  <p>Gist -> <a href="https://gist.github.com/stillhart/20aa9a1b2eeb0cff4cf5" rel="nofollow">https://gist.github.com/stillhart/20aa9a1b2eeb0cff4cf5</a></p>
  
  <p>The results are quite interesting. Could it be that ruby's uniq is quite slow?</p>
  
  <pre><code>          user     system      total        real
  uniq      23.750000   0.040000  23.790000 ( 23.823770)
  hash_uniq 18.560000   0.020000  18.580000 ( 18.591803)
  </code></pre>
  
  <p>Now my questions:</p>
  
  <ol>
  <li><p>Are there any faster ways to make an array unique?</p></li>
  <li><p>Am I doing something wrong?</p></li>
  <li><p>Is there something wrong in the Array.uniq method?</p></li>
  </ol>
  
  <p>I am using ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]</p>