From:             
Operating system: Ubuntu Natty
PHP version:      5.3SVN-2011-10-04 (SVN)
Package:          Performance problem
Bug Type:         Bug
Bug description:Iterator and ArrayAccess Interface poor perfomance than native 
array

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 bug report at https://bugs.php.net/bug.php?id=55845&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55845&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55845&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55845&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55845&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55845&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55845&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55845&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55845&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55845&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55845&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55845&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55845&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55845&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55845&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55845&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55845&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55845&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55845&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55845&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55845&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55845&r=mysqlcfg

Reply via email to