PHP Framework Comparison

I already posted some benchmarks of PHPixie comparing it to ohter popular frameworks. This time I want to show you why are some of these frameworks faster than others.

To compare the amount of boilerplate code I took the same simple application I used for benchmarking, and inserted an addition 0.01 second delay into them. As the delay always takes the same amount of time we can use it as a time reference.

The diagrams below are nested time diagrams of function execution, nested blocks represent fnctions calling one another, the size of each block represents the time the function was running. A brown block labled usleep is our hardcoded delay, so the bigger the brown block is the less time the framework took to prepare and run. You can click the images to enlarge them.

PHPixie

PHPixie was created to be very unobtrusive so our hardcoded delay occupies half of the whole execution time.

PHPixie framework benchmark

PHPixie framework benchmark

Yii

Yii framework benchmark

Yii framework benchmark

Yii took 50% longer to initialize for this basic application to run. We can see that the most of the time is wasted on autoloding classes, a lot of frameworks that make heavy use of extending classes and having a multitude of them suffer from this.

Kohana

Kohana Framework Benchmark

Kohana Framework Benchmark

Kohana wastes a lot of time searching files over the cascading file system. A lot of speed is wasted on Kohanas way of handling overriding core classes. For this very reason each class has a Kohana_Classname class and Classname class, which means twice as much files to load.

FuelPHP

FuelPHP Framework Benchmark

FuelPHP Framework Benchmark

Fuel seems to be just a bit slower than Kohana, but it seems that FuelPHPs’ cascading file system is slightly better.

Laravel

Laravel Framework Benchmark

Laravel Framework Benchmark

Laravel is going head to head with FuelPHP, but it would be interesting to compare the differences in their execution. While most delay in FuelPHP comes from autoloading, which could be overcome in the same way as it might be done for any cascading file system: by having a script that would place all class in the application folder before deployment. Laravel seems to have completely different problems. For one you might have noticed that usleep gets not just one but a few blocks in Laravel, this is because of how the controller is called (via call_user_func_array and XDebug has problems profiling such calls), this is not a problem though. You can notice some strange classes from Symfony components being instanced, you also see a glimple of mcrypt_decrypt being called etc. Basically the kind of boilerplate I was talking about in the first place.

CakePHP

CakePHP framework Benchmark

CakePHP framework Benchmark

CakePHP took 95% of the time to initialize the framework, it is almost 90% slower than PHPixie, mostly because of its rather complex architecture, there is an Event manager etc. But there are calls to Controller->__isset() occupying a lot of processing time which probably should be optimized.

As it is getting late I did not generate grind for other frameworks, I think these should suffice. Of course the tradeoff when choosing a framework is speed vs features usually, but you have to ask yourself how many times in your next project, that will likely just store and display data from the database, you will need an advanced HTTP protocol handler class or some complex class inheritance. You don’t need to go for features that you will not use just because they are there.

24 thoughts on “PHP Framework Comparison

      1. Benjamin

        Just make sure, it’s run in production mode and the caches are warmed. There is no real point in comparing the one-time-costs of compiling the DIC etc. against other frameworks.

        Reply
        1. admin Post author

          Of course. I’m not using the first call for the grind so that caches are warm for each framework that uses them.

          Reply
  1. Kjartan

    Hey…

    Great post! Can you give us details about how to do these graphical representations of function execution?

    Thanks,
    Kjartan

    ps. I am looking forward to see Symfony and Code Igniter in there

    Reply
        1. admin Post author

          CI has been discontinued, so there would really be little reason for comparisons at this point. I’ll do the ymfony2 though

          Reply
    1. admin Post author

      I’m not that familiar with Agile Tool, but It seems to me your example isn’t really ment for the web (rather CLI from what I understand) and it doesn’t actually handle anything, just instantiate itself. This way the callgrind would just show you how much time the ApiCli class takes to instantiate. It seems to me that Agile also has a MVC and ORM system, it would be much more effective to see an example using those two.

      Reply
  2. Mark Vink

    Great post!
    I did read your previous benchmark as well. I’m missing Symfony2 and Codeigniter in this comparison.

    Reply
  3. Mark Vink

    Great post!
    I read your previous benchmark as well. I’m missing Symfony2 and Codeigniter in this comparison. Could you add them?

    Reply
    1. admin Post author

      I’m currently very busy with version 2.0 (Composer based, full dependency injection etc).
      Will add the benchmarks when im done )

      Reply
  4. Chris Johnson

    Nice to see actual quantitative data like benchmarks, instead of fluffy feel-good marketing hype as the argument for or against one framework or another.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>