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.
Yii
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 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
Fuel seems to be just a bit slower than Kohana, but it seems that FuelPHPs’ cascading file system is slightly better.
Laravel
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 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.






Would be interesting to see Symfony2 up there
D
I will add it sometime later this week.
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.
Of course. I’m not using the first call for the grind so that caches are warm for each framework that uses them.
I hope to see code igniter
Will add that one by the end of the week too =)
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
You can read more about them here:
http://www.xdebug.org/docs/profiler
I’ll be adding codeigniter and symfony this week
Please, post how you’re doing this benchmarks.
You basically install XDebug, enable profiling in your php.ini and then you can visualize the callgrind logs that it producec on each page load. There is a manual for installing XDebug and visualizing with KCacheGrind here: http://www.xdebug.org/docs/profiler
Great job PHPixie
Try benchmarking Agile Toolkit (agiletoolkit.org), here is the code:
include’atk4/loader.php’;
$api = new ApiCLI();
usleep(0.01);
Amazing graphing tool!
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.
Could you put appropriate versions next to the frameworks? Thanks.
I mentioned versions in previous benchmark
Great post!
I did read your previous benchmark as well. I’m missing Symfony2 and Codeigniter in this comparison.
Great post!
I read your previous benchmark as well. I’m missing Symfony2 and Codeigniter in this comparison. Could you add them?
I’m currently very busy with version 2.0 (Composer based, full dependency injection etc).
Will add the benchmarks when im done )