Forked from julian7/include-vs-cover-vs-between.rb
Created
November 12, 2012 08:23
-
-
Save muratguzel/4058129 to your computer and use it in GitHub Desktop.
include? vs. cover? vs. between?
This file contains hidden or 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 'date' | |
require 'benchmark' | |
n = 1_000_000 | |
start_date = Date.new(2012, 01, 01) | |
end_date = Date.new(2012, 03, 01) | |
act_date = Date.new(2012, 02, 01) | |
Benchmark.bm(10) do |x| | |
x.report('include?') do | |
n.times do | |
(start_date..end_date).include? (act_date) | |
end | |
end | |
x.report('cover?') do | |
n.times do | |
(start_date..end_date).cover? (act_date) | |
end | |
end | |
x.report('between?') do | |
n.times do | |
act_date.between?(start_date, end_date) | |
end | |
end | |
end |
This file contains hidden or 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
js@horadrim [~/Code] % ruby ./include-vs-cover-vs-between.rb | |
user system total real | |
include? 38.910000 0.130000 39.040000 ( 40.826650) | |
cover? 1.100000 0.000000 1.100000 ( 1.147182) | |
between? 0.630000 0.010000 0.640000 ( 0.642790) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment