Skip to content

Instantly share code, notes, and snippets.

@mje113
Created June 4, 2014 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mje113/4ca9fd1f4279ff31a40d to your computer and use it in GitHub Desktop.
Save mje113/4ca9fd1f4279ff31a40d to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
require 'securerandom'
require 'set'
Benchmark.ips do |x|
sizes = [ 2, 8, 32, 128, 512 ]
sizes.map! { |size| a = [].tap { |a| size.times { a << SecureRandom.uuid } } }
sizes.each do |size|
x.report("new set: #{size.size}") do
set = Set.new(size)
set.include?('a')
end
x.report("new arry: #{size.size}") do
arry = size
arry.include?('a')
end
set = Set.new(size)
x.report("set: #{size.size}") do
set.include?('a')
end
x.report("arry: #{size.size}") do
arry = size
arry.include?('a')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment