Comments (5)
Hi!
Did you create your library because you were not happy with this specific implementation? I'm curious if you're able to share how your library is different?
Indeed that is the reason I created it. Happy to discuss this in more details, but first a little disclaimer: I created this lib a couple of years ago, and I haven't checked the status of the other libraries recently, so my comments here might be outdated.
- None of the libraries I tried back then behaved like a generator, i.e. had the ability to be used in a
foreach
to calculate, process, calculate, process, etc. They all required you to build a array of occurrences first which means it's "calculate, calculate, calculate" and then "process, process, process". It is very inefficient because you have to wait for the entire set to be ready before starting processing it. Consequently, it also means it was impossible to handle infinite rules properly, which was a requirement for my project. - In addition, none of the librairies were implementing the RFC entirely (or they did but in a really buggy way), which again was a requirement for my project.
- Last but not least, some libraries rely on PHP's date functions to perform some calculations, which are extremely slow. This library only uses arithmetic operations.
I remember trying the lib you mentioned. It was slow and completely over-engineered. Quite frankly I absolutely hated the very verbose interface with way too much bloat. Case in point: it requires doctrine/collections - this is a major code smell for me, I like to keep things simple.
After looking a various Ruby implementations (which suffered the same problem from PHP ones), I discovered the Python version which was built around a generator and had everything I needed, so I just ported it and adapted it for PHP. All the credit for the algorithm go to them, they did an amazing job.
Does this library do things any different?
No not really, because actually this is the correct way to do it, as surprising as it sounds. Recurrence rules can be very tricky and the only way to calculate the occurrences 5 years from the starting date is to actually compute 5 years worth of occurrences.
How's the performance for large date ranges like this?
Depends what you call "poor performance", how long does it take at the moment? Weekly rules should be fast. There is only 52 occurrences per year, so roughly 260 iterations over 5 years - that's very quick if the lib is coded well, and not a large date range by any mean. I did a quick test, my lib handles that in about 20ms on my development virtual machine, which is a perfectly acceptable performance for me. Code is below if you want to test with your own rule.
$start = microtime(true);
$iter = 10; // trying 10 times to get an average
for ( $i = 0; $i < $iter; $i++ ) {
$rule = new RRule\RRule([
'FREQ' => 'WEEKLY',
'INTERVAL' => 1,
'BYDAY' => 'FR',
'DTSTART'=> '2010-01-01' // over 7 years ago
]);
$rule->getOccurrencesBetween('2017-11-01', '2017-11-30'); // occurrences this month
}
$stop = microtime(true);
echo "Average ".(($stop-$start)/$iter).'s';
Let me know, I'm curious to know how it compares!
from php-rrule.
You sir, are a legend @rlanvin! Add me to your fan library. ❤️
from php-rrule.
Hey thanks! I very much appreciate the detailed answer. That's quite helpful.
From my initial testing this library appears to be, at a minimum, 2.5x faster, and sometimes as high as 5x faster. That's pretty significant.
I'm going to give this library a try on a new project an see how it goes! 👍
from php-rrule.
From my initial testing this library appears to be, at a minimum, 2.5x faster, and sometimes as high as 5x faster. That's pretty significant.
Wow! That's nice to hear. I never really took the time to compare performances with other libs, maybe I'll run benchmarks at some point. :)
I'm going to give this library a try on a new project an see how it goes!
Great! Feel free to open more issues if you have questions. Suggestions and pull requests are always welcome.
from php-rrule.
@mrajabtech Well thank you!
from php-rrule.
Related Issues (20)
- addExRule not working for me HOT 4
- Drop support for PHP < 7.3 HOT 2
- Daylight Savings Time issue with PHP 8.1 HOT 13
- How to create Rrule for every day from X to Y? HOT 4
- How to use exdate with byhour? HOT 3
- Question: Performance optimization when calculating occurrences using multiple rules HOT 3
- exRule and addRule conflict HOT 3
- More forgiving DTSTART behavior when using only date for UNTIL HOT 2
- Nested exrules HOT 2
- occursAt sometimes failing HOT 2
- Problem with getOccurrencesAfter HOT 9
- Removing all dates that are inside a DatePeriod from Rset HOT 1
- bi-weekly occurance wrong HOT 3
- dtstart vs. Repeat Dates / Current Time Not Considered in Calculation HOT 5
- humanreadable not so much HOT 2
- Looking for a way to add DTEND HOT 1
- Exrul not working
- Add alias methods for better reading of code HOT 1
- Legacy Code - Can I 'require_once' instead of composer ? HOT 2
- Danish translation file attached
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-rrule.