As I wanted to set up a system to benchmark PHPixie I decided I might as well benchmark other frameworks too. Performance comparison done by Yii developers is laughable at best, because they benchmarked the “Hello World” scenario which tells nothing about database access speed, ORM performance or view rendering. This is really biased towards frameworks that lazy load classes and modules on first request to them. If the framework initializes slower it doesn’t mean it works slower too. Thats why:
We will benchmark a complete scenario that includes parsing URL parameters, getting data from the database and rendering a view.
Also I will not be testing this on a dedicated machine but on a VPS with limited resources. Why? Because that’s where a lot of website end up. So here is the setup:
Framework versions benchmarked:
We will run a test application that will have to take a parameter from the URL and output the record from the database. We will have a Fairy table with two columns: id and name. The URL will be http://test/fairies/get/1 and we expect to get the name of the first fairy from the database. This way we can test routing speed and database access. Here we go:
PHP Framework Performance with XCache
Well it seems that Yiis’ claims are a bit overhyped, it is indeed faster then most frameworks, but the difference is not as drastic now. I’ve been hearing a lot about Laravel 4 lately, but the results that I came up with Laravel 3 were mostly the same.
So now let’s try without the XCache:
PHP Framework Benchmark without opcache
As you can see the difference is quite larger this time. PHPixie is approximately twice as fast as Zend. Why so? Mostly because we update the code all the time to tweek little things that hog miliseconds of performance, for example trying to use str_replace instead of preg_replace where possible, etc.
Let me say a few words about my personal thoughts.
CakePHP has very good documentation, I’ve created few sites with it some time in the past, and it seems a decent system, but it does kick you in soft places a few times, mostly because you can find a lot of tutorials on the internet that are in fact for its older version and don’t work with the new release. Their database abstraction feels a bit dated and doesn’t really provide a convenient way of querying the database, especially when passing params to find() as array. You don’t get any hints when doing that (like code completion when using query builders in other frameworks) and have to remember those parameters which means consulting the API a lot, which doesn’t seem developer friendly.
Yii was annoying for me to code in. Mostly because i hate code generation. Even today when i tried to do this simple application to benchmark I got this pregenerated website with contact form and about page etc, and had to spend time to actually not use it, it felt like I was modding a CMS rather than coding my own code. On the other hand generated models do seem to be a workable idea so I can’t hold this against Yii. Another thing that bugs me about it is naming things like Gii etc. The name doesn’t describe at all what it does. Also it is really hard to find a tutorial that actually tells you which code to write rather they tell you which buttons to press to generate the code, and leave you wondering how to actually do the customization part.
Codeigniter was super awesome back in the day, it was simple, elegant, everything. It’s still pretty good now but some developers complain about it moving slowly with PHP focusing on backwards compatibility. IMHO apart from the namespaces there’s little reason for a framework to force PHP 5.3 on you and there is nothing really groundbreaking in PHP 5.4, except for maybe traits. But Codeigniter still feels dated though, especially its ActiveRecord implementation. PHPixie follows a lot of Kohana practices which follows CodeIgniter, so you might say that CI is PHPixies’ grandad.
Kohana is something that I like and have used a lot. The tutorials are for the most part non-existent, but it’s rather intuitive to write in. What I really liked is the lack of master page layout by default, like those that CakePHP and Yii have, which is good because you usually define it yourself by extending a Controller, so you have more control over it.
Laravel I didn’t like, there’s just no edge to it apart from branding. They seem so consumed by branding and naming everything those strange names, e.g. Eloquent and Blade. They keep on telling you that their bundle system is the best and their ActiveRecord implementation is the best when it’s more or less same thing as you would expect from any framework, e.g. eager loading is a cool idea but it has been in Kohana since a long time and Yii too. I can’t smile enough when I see the “A Framework For Web Artisans” and “All the cool kids are doing it” punchlines. I assume the idea is to use coolness as a factor e.g. like Apple does. What is really good about Laravel is detailed configuration files which other frameworks lack in comparison.
Zend is still being Zend. It is slow but has extensive libraries, large community and a lot of good documentation. I don’t think anyone uses it for small to medium projects though.
Symfony is still slow, though it targets the same enterprise niche as Zend does. I never used Twig, as PHP is a very good templating language on its own, the idea of declaring templates is rather useful though, and looks much better then using includes inside PHP. Using Doctrine was also a choice of sacrificing speed for stability. If I had to choose between it and Zend though I would pick Symfony because it seems a bit more straightforward for the developer (e.g. me).
Now where does PHPixie fit in? If you know that your application will have no use for the complex stacks of frameworks like Zend, that all you actually will use is mostly database access and showing pages and making AJAX calls you need something that does just that, something that let’s you built upon what you decide is best and let’s you deploy applications fast. If further down the line you come across that you actually need an additional feature you can easily add a library to PHPixie with no hustle at all. On the other hand large projects usually tend to have their own implementation of virtually everything and PHPixie can provide a very strong foundation for that.