CI版本是2.1.3,thinkphp用的是3.1。 php
由於大多數站點所作的事情就是查詢數據庫,所以這次的測試着重於數據庫查詢並顯示。測試的數據庫是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>"; ?>
我在自建的入口文件裏填寫以下代碼: mysql
$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的關鍵代碼以下 sql
<?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次的訪問時間以下: thinkphp
11.565332031250 (PHP) 數據庫
54.319799804790 (CI) 安全
132.997436523438 (ThinkPHP) 框架
ThinPHP與PHP 測試
132.997436523438/11.565332031250=11.499664355859 約等於11.5倍 fetch
那麼也就是說,純PHP是CI的4.5是ThinkPHP的11.5倍 ui
我想仍是我本身寫個簡單的框架吧,可以完成開發效率就OK的框架吧。