CI版本是2.1.3,thinkphp用的是3.1。
因为大多数站点所做的事情就是查询数据库,因此此次的测试着重于数据库查询并显示。测试的数据库是dede的sys_enum,631条数据。目标就是查询出这些数据并显示到页面上计算消耗时间。<?php $begin=microtime(); $begin=microtime_float($begin); ?> <?php function microtime_float($time) { list($usec, $sec) = explode(" ", $time); return (((float)$usec + (float)$sec)*1000); } ?> <?php $link = mysql_connect('localhost', 'root', 'founder') or die('Could not connect: ' . mysql_error()); mysql_select_db('dedecmsv57utf8sp1') or die('Could not select database'); $query='SELECT * FROM dede_sys_enum'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); echo "<table width=\"416\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr><td>ID</td><td>ename</td><td>egroup</td></tr>"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; mysql_free_result($result); mysql_close($link); $end=microtime(); $end=microtime_float($end); echo 'time:'.($end-$begin); ?>
<?php $begin=microtime(); $begin=microtime_float($begin); ?>
$end=microtime(); $end=microtime_float($end); echo 'time:'.($end-$begin); ?>
class Test extends CI_Controller { public function index() { $this->load->model('testm'); $data['test']=$this->testm->testmf(); $this->load->view('test',$data); } }
class Testm extends CI_Model { public function testmf() { $this->load->database(); $sql="SELECT * FROM dede_sys_enum"; return $this->db->query($sql); } }
<?php foreach($test->result() as $row) echo "<tr><td>".$row->id."</td><td>".$row->ename."</td><td>".$row->evalue."</td><td>".$row->egroup."</td><td>".$row->disorder."</td><td>".$row->issign."</td></tr>"; ?>
我在自建的入口文件里填写如下代码:
$begin=microtime(); $begin=microtime_float($begin); function microtime_float($time) { list($usec, $sec) = explode(" ", $time); return (((float)$usec + (float)$sec)*1000); } require("./tp/ThinkPHP.php"); $end=microtime(); $end=microtime_float($end); echo 'time:'.($end-$begin);然后按要求做了action
class IndexAction extends Action { public function index(){ $Sys_enum=new Model("sys_enum"); $list =$Sys_enum->select(); $this->assign('test', $list); $this->display(); } }
还有View的关键代码如下
<?php foreach($test as $row) echo "<tr><td>".$row['id']."</td><td>".$row['ename']."</td><td>".$row['evalue']."</td><td>".$row['egroup']."</td><td>".$row['disorder']."</td><td>".$row['issign']."</td></tr>"; ?>
得到10次的访问时间如下:
11.565332031250 (PHP)
54.319799804790 (CI)
132.997436523438 (ThinkPHP)
ThinPHP与PHP
132.997436523438/11.565332031250=11.499664355859 约等于11.5倍
那么也就是说,纯PHP是CI的4.5是ThinkPHP的11.5倍