Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created March 2, 2018 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save djberg96/382557d33b91ca8cb642d6a84cf89fbc to your computer and use it in GitHub Desktop.
Save djberg96/382557d33b91ca8cb642d6a84cf89fbc to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
require 'set'
ary = []
5000.times { ary << rand.round(6) }
set = ary.to_set
Benchmark.ips do |x|
x.report("Array#include?") { ary.include?(rand.round(6))}
x.report("Set#include?") { set.include?(rand.round(6))}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment