Yii is a high-performance framework. The graph below shows how efficient Yii is when compared with other popular PHP frameworks. In the graph, RPS stands for "request per second" which describes how many requests an application written in a framework can process per second. The higher the number, the more efficient a framework is. As we can see that Yii outperforms all other frameworks in this comparison. The performance advantage of Yii is especially significant when the widely used APC extension is enabled.
Performance alone is not the whole story (otherwise we should all use plain HTML or PHP). With such superior performance, Yii still provides a very rich feature set which can greatly improve your development efficiency.
Yii is so much faster because it is using the lazy loading technique extensively. For example, it does not include a class file until the class is used for the first time; and it does not create an object until the object is accessed for the first time. Other frameworks suffer from the performance hit because they would enable a functionality (e.g. DB connection, user session) no matter it is used or not during a request.
Below we explain how we design the benchmark applications and obtain the above RPS figures.
Since our goal is to compare the minimal overhead of each framework, the benchmark application for each framework should be the simplest one. We choose to display a "Hello World" text string by placing an
echo statement in the default action of each application. Any additional framework features (e.g. session) are disabled to ensure fairness of the comparison. To obtain a copy of the benchmark applications, please check out the phpmark project.
We choose to do "Hello World" testing mainly to achieve our goal, i.e., to find out the minimal overhead of each framework. Many people complain that the "Hello World" application is meaningless because a real-world application often needs to deal with more complex tasks, such as database queries. This is not very true. In reality, especially in a large-scale Web 2.0 application, we often encounter scenarios that are very close to "Hello World". For example, an application may need to respond to an AJAX request that should return the current server timestamp; a page has a large portion of its content being cached and an application just needs to fetch the cached content and display it.
Another reason for "Hello World" is because when more complex features (e.g. database queries) are involved, it becomes a very difficult task to ensure the comparison is fair. For example, one framework could be very efficient at performing database queries, but it lacks caching scheme; while another framework is a bit slower with database queries, but it has sophisticated caching feature to help ease the performance hit. There are simply too many factors involved to conduct a fair comparison.
The RPS numbers were obtained using the ApacheBench tool with the command "
ab -t 30 -c 10 URL" (i.e., at concurrency level 10 running the test for 30 seconds). To get the number for each framework, we first stop and then start the Apache Web server to avoid interference. We also run the test application for a few times to "warm up" the testing environment. In the phpmark project, we have a shell script named
benchmark.sh to automate the benchmarking procedure.
The testing environment is as follows:
The APC ini settings are as follows:
apc.enabled=1 apc.shm_segments=1 apc.optimization=0 apc.shm_size=32 apc.ttl=7200 apc.user_ttl=7200 apc.num_files_hint=1024 apc.mmap_file_mask=/tmp/apc.XXXXXX apc.enable_cli=1 apc.cache_by_default=1 apc.stat=0