Bug #55845 [Opn->Bgs]: Iterator and ArrayAccess Interface poor perfomance than native array
Edit report at https://bugs.php.net/bug.php?id=55845&edit=1
ID: 55845
Updated by: aharvey@php.net
Reported by: support at freelancecode dot cz dot cc
Summary: Iterator and ArrayAccess Interface poor perfomance
than native array
-Status: Open
+Status: Bogus
Type: Bug
Package: Performance problem
Operating System: Ubuntu Natty
PHP Version: 5.3SVN-2011-10-04 (SVN)
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Yep, it is.
Previous Comments:
------------------------------------------------------------------------
[2011-10-04 15:28:02] support at freelancecode dot cz dot cc
Description:
------------
Hi there,
I want to report that implements native interface for Iterator and ArrayAccess, seriously damage cpu
perfomance (compared to native array: absolutely huge).
Use my attached-class for testing for 300 array records, then perfomance suffered.
Test script:
---------------
<?php
namespace Entity;
abstract class ListArray implements \Iterator, \ArrayAccess, \Countable, \Serializable
{
private
$container = array();
final public function __construct($data = array())
{
$this->doConstruct($data);
}
function __clone() { }
protected function doConstruct($data)
{
$this->container = array_merge((array) $data, $this->container);
}
function __set($key, $val)
{
$this->container[$key] = $val;
}
public function rewind()
{
reset($this->container);
}
public function current()
{
return current($this->container);
}
public function key()
{
return key($this->container);
}
public function next()
{
next($this->container);
}
public function valid()
{
return (key($this->container) !== NULL);
}
public function offsetGet($offset)
{
return isset($this->container[$offset])? $this->container[$offset] : NULL;
}
public function offsetSet($offset, $value)
{
if(is_null($offset))
{
$this->container [] = $value;
}
else
{
$this->container [$offset] = $value;
}
}
public function offsetExists($offset)
{
return isset($this->container[$offset]);
}
public function offsetUnset($offset)
{
unset($this->container[$offset]);
}
public function count()
{
static $count;
return ++$count;
}
public function filter($typ)
{
$result = array();
$this->rewind();
while($this->valid())
{
if(stripos($this->key(), $typ) !== FALSE) $result[$this->key()] =
$this->current();
$this->next();
}
return $result;
}
public function serialize()
{
$props = array();
foreach($this as $key => $val)
{
$props [$key] = $val;
}
return serialize(array($this->container, $props));
}
public function unserialize($data)
{
list($this->container, $props) = unserialize($data);
foreach($props as $key => $val)
{
$this->$key = $val;
}
}
}
Expected result:
----------------
Significant perfomance like native-array
Actual result:
--------------
Poor perfomance, absolutely different from native-array
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55845&edit=1
Thread (2 messages)