class object vs array for db table model

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,

It's been a couple years since I've did a project in PHP.  The current
project I'm working on is for PHP 5.3 and I noticed a performance issue.  Is
it just me or is there a BIG difference in performance between class object
vs array for PHP 5.3?  Below is the sample:

class MyTable
{
	private $_id; // int
	private $_name; // varchar
	private $_description; // text

	public  function __construct() {}

	public function getId()
	{
		return $this->_id;
	}
	public function getName()
	{
		return $this->_name;
	}
	public function getDescription()
	{
		return $this->_description;
	}

	public function setId($id)
	{
		$this->_id = $id;
	}
	public function setName($name)
	{
		$this->_name = $name;
	}
	public function setDescription($description)
	{
		$this->_description = $description;
	}
}

$my_table = array ('id' => 'id value', 'name' => 'name value', 'description'
=> 'long description text');

The above are representations for my table as class and as array,
respectively.  The only difference is how I represent the results from db:

1) as class object
$list = array();
while ($row = $db->fetch($result))
{
	$my_table = new MyTable();
	$my_table->setId($row['id']);
	$my_table->setName($row['name']);
	$my_table->setDescription($row['description']);
	
	$list[$my_table->getId()] = $my_table;
}

2) as table
$list = array();
while ($row = $db->fetch($result))
{
	$my_table['id'] = $row['id'];
	$my_table['name'] = $row['name'];
	$my_table['description'] = $row['description'];
	
	$list[$my_table['id'] = $my_table;
}

The performance difference I get is about 1.4 seconds with the array in the
lead!!!  Does anyone have the same problem? 

Thanks,
Tommy

PS: The above executed in 4.2 sec and 1.8 sec (on average) respectively w/o
actually showing the results to html, while my ASP.NET project executes it
and displays in html in about 2 seconds for all 3684 rows, using class
similar to the MyTable.  All codes, PHP & ASP.NET C#, access the same MySQL
DB on the same development box.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux