Created
March 18, 2015 02:23
-
-
Save rShetty/b2d8084f417d269d296f to your computer and use it in GitHub Desktop.
include? vs cover?
This file contains 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' | |
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