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 was created to be very unobtrusive so our hardcoded delay occupies half of the whole execution time.
PHPixie 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 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 Framework Benchmark
Fuel seems to be just a bit slower than Kohana, but it seems that FuelPHPs’ cascading file system is slightly better.
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 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.