Giter Site home page Giter Site logo

Performance? about php-rrule HOT 5 CLOSED

reinink avatar reinink commented on August 25, 2024 2
Performance?

from php-rrule.

Comments (5)

rlanvin avatar rlanvin commented on August 25, 2024 8

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.

iamroi avatar iamroi commented on August 25, 2024 1

You sir, are a legend @rlanvin! Add me to your fan library. ❤️

from php-rrule.

reinink avatar reinink commented on August 25, 2024

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.

rlanvin avatar rlanvin commented on August 25, 2024

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.

rlanvin avatar rlanvin commented on August 25, 2024

@mrajabtech Well thank you!

from php-rrule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.