Skip to content

Instantly share code, notes, and snippets.

@brandonc
Last active December 19, 2015 21:48
Show Gist options
  • Save brandonc/6022588 to your computer and use it in GitHub Desktop.
Save brandonc/6022588 to your computer and use it in GitHub Desktop.
Rehearsal ----------------------------------------
uniq 0.270000 0.000000 0.270000 ( 0.278307)
set 0.310000 0.010000 0.320000 ( 0.314648)
------------------------------- total: 0.590000sec
user system total real
uniq 0.220000 0.000000 0.220000 ( 0.230810)
set 0.300000 0.000000 0.300000 ( 0.310188)
require 'benchmark'
def make_array
(1..10000).map { Random.rand(10) }
end
Benchmark.bmbm do |x|
x.report("uniq") do
array = []
100.times do
array.concat(make_array)
end
array.uniq
end
x.report("set") do
require 'set'
set = Set.new
100.times do
set.merge(make_array)
end
set.to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment