Created
June 22, 2015 16:27
-
-
Save meinac/0f4806f6c812b65db4d8 to your computer and use it in GitHub Desktop.
Array.uniq.to_set vs Array.to_set
This file contains hidden or 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
require 'benchmark/ips' | |
require 'set' | |
#init array | |
arr = Array.new | |
1000.times do | |
arr << (rand * 20).to_i | |
end | |
Benchmark.ips do |x| | |
x.config(:time => 10, :warmup => 2) | |
x.report("Array") do | |
arr.uniq.to_set | |
end | |
x.report("Set") do | |
arr.to_set | |
end | |
x.compare! | |
end |
Author
meinac
commented
Jun 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment