Skip to content

Instantly share code, notes, and snippets.

@rShetty
Created March 18, 2015 02:23
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 rShetty/b2d8084f417d269d296f to your computer and use it in GitHub Desktop.
Save rShetty/b2d8084f417d269d296f to your computer and use it in GitHub Desktop.
include? vs cover?
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
x.time = 5
x.warmup = 2
no_of_times = 1_000_000
last_value = 10000
x.report("include?") do
no_of_times.times do
(1 .. last_value).include?(5666)
end
end
x.report("cover?") do
no_of_times.times do
(1 .. last_value).cover?(5666)
end
end
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment