1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
<?php
set_include_path(implode(PATH_SEPARATOR, array(
realpath('D:/Dev/Lib/ZendFramework-1.9.5/library'),
get_include_path(),
)));
require_once('Zend/Registry.php');
require_once('Zend/Db/Adapter/Pdo/Mysql.php');
require_once('Zend/Db/Table.php');
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => 'root',
'dbname' => 'dbtest'
));
Zend_Db_Table::setDefaultAdapter($db);
class test
{
private $_table = null;
public function __construct()
{
$this->_table = new Zend_Db_Table('account');
}
public function getRow()
{
$select = $this->_table->select()
->from($this->_table->info('name'))
->where("acc_id = ?", '0');
return $this->_table->fetchRow($select);
}
}
# Fonction de test pour N instances de la classe "test"
# et N appels à la méthode getRow()
function run1($i)
{
$list = array();
for ($j=0;$j<=$i;$j++) {
$test = new test();
$row = $test->getRow();
$list[] = $test;
}
}
# Fonction de test pour 1 instance de la classe "test"
# et N appels à la méthode getRow()
$test = new test();
function run2($i)
{
$list = array();
global $test;
for ($j=0;$j<=$i;$j++) {
$row = $test->getRow();
$list[] = $test;
}
}
$start = memory_get_usage(true);
echo "[START] memory : " . round(($start)/1024,2) . " ko<br />";
run1(10000);
//run2(10000);
$end = memory_get_usage(true);
echo "[END] memory : " . round(($end)/1024,2) . " ko<br />";
echo "[DIFF] " . round(($end-$start)/1024,2) . " ko<br />";
echo "[PIC] " . round(memory_get_peak_usage(true)/1024,2) . " ko<br />"; |
Partager