Dear all I told you I’m trying to run more practical test on yii to show what is the gap between it’s performance with other frameworks and raw php here is the result. my test server was a Windows7 Home Premium machine with intel corei7 1.6GHz up to 2.8GHz CPU and 4GB DDR3 RAM running XAMPP with PHP 5.3.1, Apache 2.2.14, MySQL 5.1.41
database has been generated bycode below.
<?php
/**
* @author phpveteran
* @copyright 2010
*/
/* Connecting, selecting database */
$db_link = mysql_connect("localhost", "root", "ringsport");
if (!$db_link) {
die("Could not connect: " . mysql_error());
}
mysql_select_db("benchmarking") or die("Could not select database");
set_time_limit(0);
/* Performing SQL query */
for($i=29;$i<50000;$i++){
$base='ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
$max=strlen($base)-1;
mt_srand((double)microtime()*1000000);
$rand_text='';
while (strlen($rand_text)<251)
$rand_text.=$base{mt_rand(0,$max)};
$query = "INSERT INTO `benchmarking`.`text_var` (
`id` ,
`random_var` ,
`random_text`
)VALUES (
NULL , '$rand_text', '$rand_text');";
mysql_query($query);
}
/* Closing connection */
mysql_close($db_link);
?>
Raw PHP:
<?php
/**
* @author phpveteran
* @copyright 2010
*/
/* Connecting, selecting database */
$db_link = mysql_connect("localhost", "root", "ringsport");
if (!$db_link) {
die("Could not connect: " . mysql_error());
}
mysql_select_db("benchmarking") or die("Could not select database");
set_time_limit(0);
/* Performing SQL query */
$query = "SELECT * FROM `text_var` WHERE `random_var` = '6CEM3cjkRSg8gLgDSMSyQHwSCeNaPrRhKPMFShQYSFygqZhwY4NWpweEENCSxMghMqfOB9K2tQ6kNCfEnqtaSTMMKdnEhwfQfKnsnBQr2ZATE1ARcKLbfT417tpHDQ4hPe3jScMZHZEpLpn8sMs8QDPSyWkQNjWqqCLGtn3sAkKD1fSbk14TamcKEHn5c2txDEEaswwtQKLfQKgmfXEp3nwq8HMNYxTSkDSY3ZBRMhKNb55H1tM2zcG8Za'";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
var_dump($row);
}
/* Closing connection */
//mysql_close($db_link);
?>
Yii clean and fresh setup SiteController.php and actionIndex
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
//$this->render('index');
$connection=new CDbConnection('mysql:host=localhost;dbname=benchmarking','root','ringsport');
$connection->active=true;
$dataReader = $connection->createCommand("SELECT * FROM `text_var` WHERE `random_var` = '6CEM3cjkRSg8gLgDSMSyQHwSCeNaPrRhKPMFShQYSFygqZhwY4NWpweEENCSxMghMqfOB9K2tQ6kNCfEnqtaSTMMKdnEhwfQfKnsnBQr2ZATE1ARcKLbfT417tpHDQ4hPe3jScMZHZEpLpn8sMs8QDPSyWkQNjWqqCLGtn3sAkKD1fSbk14TamcKEHn5c2txDEEaswwtQKLfQKgmfXEp3nwq8HMNYxTSkDSY3ZBRMhKNb55H1tM2zcG8Za'")->query();
while($row=$dataReader->read()){
var_dump($row);
}
exit;
}
Zend framework fresh and clean IndexController.php indexAction
public function indexAction()
{
// action body
set_time_limit(0);
require_once 'Zend/Db.php';
$db = Zend_Db::factory('Mysqli',
array(
'host' => 'localhost',
'dbname' => 'benchmarking',
'username'=> 'root',
'password' => 'ringsport')
);
$stmt = $db->query("SELECT * FROM `text_var` WHERE `random_var` = '6CEM3cjkRSg8gLgDSMSyQHwSCeNaPrRhKPMFShQYSFygqZhwY4NWpweEENCSxMghMqfOB9K2tQ6kNCfEnqtaSTMMKdnEhwfQfKnsnBQr2ZATE1ARcKLbfT417tpHDQ4hPe3jScMZHZEpLpn8sMs8QDPSyWkQNjWqqCLGtn3sAkKD1fSbk14TamcKEHn5c2txDEEaswwtQKLfQKgmfXEp3nwq8HMNYxTSkDSY3ZBRMhKNb55H1tM2zcG8Za'");
$stmt->execute();
while ($data = $stmt->fetchAll()) {
var_dump($data);
}
exit;
}
now bench marking result:
Raw PHP:
C:\xampp\apache\bin>ab -t 20 -c 4 http://localhost/random_text/index.php
Benchmarking localhost (be patient)
Finished 125 requests
Concurrency Level: 4
Time taken for tests: 20.585 seconds
Complete requests: 125
Failed requests: 0
Write errors: 0
Total transferred: 155575 bytes
HTML transferred: 117856 bytes
Requests per second: 6.07 [#/sec] (mean)
Time per request: 658.726 [ms] (mean)
Time per request: 164.681 [ms] (mean, across all concurrent requests)
Transfer rate: 7.38 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 1
Processing: 596 642 58.2 632 878
Waiting: 596 642 58.1 631 877
Total: 596 643 58.2 632 878
Percentage of the requests served within a certain time (ms)
50% 632
66% 634
75% 654
80% 678
90% 711
95% 745
98% 877
99% 878
100% 878 (longest request)
Yii Framework
C:\xampp\apache\bin>ab -t 20 -c 4 http://yii.local/index.php
Benchmarking yii.local (be patient)
Finished 109 requests
Concurrency Level: 4
Time taken for tests: 20.322 seconds
Complete requests: 109
Failed requests: 0
Write errors: 0
Total transferred: 133525 bytes
HTML transferred: 101152 bytes
Requests per second: 5.36 [#/sec] (mean)
Time per request: 745.767 [ms] (mean)
Time per request: 186.442 [ms] (mean, across all concurrent requests)
Transfer rate: 6.42 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 1
Processing: 630 728 104.4 709 1047
Waiting: 630 727 104.3 709 1047
Total: 630 728 104.4 709 1047
Percentage of the requests served within a certain time (ms)
50% 708
66% 730
75% 777
80% 822
90% 888
95% 955
98% 1047
99% 1047
100% 1047 (longest request)
Zend Framework
C:\xampp\apache\bin>ab -t 20 -c 4 http://zf.local/index.php
Benchmarking zf.local (be patient)
Finished 49 requests
Concurrency Level: 4
Time taken for tests: 20.722 seconds
Complete requests: 49
Failed requests: 0
Write errors: 0
Total transferred: 64821 bytes
HTML transferred: 49674 bytes
Requests per second: 2.36 [#/sec] (mean)
Time per request: 1691.607 [ms] (mean)
Time per request: 422.902 [ms] (mean, across all concurrent requests)
Transfer rate: 3.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 1299 1608 230.1 1599 2091
Waiting: 1298 1607 230.0 1598 2089
Total: 1299 1608 230.1 1600 2091
Percentage of the requests served within a certain time (ms)
50% 1534
66% 1679
75% 1733
80% 1754
90% 1910
95% 2090
98% 2091
99% 2091
100% 2091 (longest request)