Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.