Allow a floor_date to be passed to RRule#each, for performance
Previously, methods like between would enumerate from dtstart
onward, which lead to an O(n) problem (where n is the length of
time between dtstart and between(start_date)). This allows a
floor date to be passed, which is used to build the context for the
Enumerable, allows us to floor the Enumerator as needed
However, this performance improvement can only be used if the RRULE
does not have a COUNT or INTERVAL option, because both of those
options require us to start iterating from the dtstart in order to
return the correct results
Added some basic tests of how the Enumerator handles the
floor_date
Below are 2 runs of scripts/benchmark.rb, the first is this PR, the second is the current version (0.3.0)
$ git log -1 --pretty=oneline
a678a782070168fd2090b69968153d9a027bcd2e Allow a floor_date to be passed to `RRule#each`, for performance
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12:01:00
$ ruby scripts/benchmark.rb
Benchmarking rules in version 0.3.0: 1000 expansions over one month
user system total real
FREQ=WEEKLY 0.270000 0.010000 0.280000 ( 0.277578)
FREQ=WEEKLY;BYDAY=WE 0.430000 0.000000 0.430000 ( 0.429060)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12:01:10
$ git checkout 19e3e8d67dcf4810bbe65c20c851b50fbe0bce35
$ git log -1 --pretty=oneline
19e3e8d67dcf4810bbe65c20c851b50fbe0bce35 Merge pull request #9 from square/rmitchell/bump-version
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12:01:30
$ ruby scripts/benchmark.rb
Benchmarking rules in version 0.3.0: 1000 expansions over one month
user system total real
FREQ=WEEKLY 7.150000 0.040000 7.190000 ( 7.210978)
FREQ=WEEKLY;BYDAY=WE 12.440000 0.080000 12.520000 ( 12.564897)
Allow a floor_date to be passed to
RRule#each
, for performancebetween
would enumerate fromdtstart
onward, which lead to an O(n) problem (wheren
is the length of time betweendtstart
andbetween(start_date
)). This allows a floor date to be passed, which is used to build the context for theEnumerable
, allows us to floor the Enumerator as neededdtstart
in order to return the correct resultsfloor_date
Below are 2 runs of
scripts/benchmark.rb
, the first is this PR, the second is the current version (0.3.0)