note 102747 added to class.arrayobject

From: Date: Thu, 03 Mar 2011 12:38:16 +0000
Subject: note 102747 added to class.arrayobject
Groups: php.notes 
Request: Send a blank email to php-notes+get-177525@lists.php.net to get a copy of this message
I don't believe the same performance is true since PHP 5.3. Using the same fill, read_key and foreach approach on both native arrays and ArrayObjects with 10000 keys I get the following PHP 5.2 array() fill 0.013101 array() read 0.008685 array() foreach 0.004319 ArrayObject fill 0.014136 ArrayObject read 0.010003 ArrayObject foreach 3.454612 PHP 5.3 array() fill 0.010395 array() read 0.005933 array() foreach 0.001903 ArrayObject fill 0.010598 ArrayObject read 0.006387 ArrayObject foreach 0.003451 This was the code I used for both, an array or ArrayObject is passed into each of the functions. Again PEAR::Benchmark was used to get the results. <?php require_once 'Benchmark/Timer.php'; define('KEYS', 10000); function fill(&$arr) { for ($i = 1; $i <= KEYS; $i++) { $arr['key-' . $i] = $i; } } function read_key(&$arr) { for ($i = 1; $i <= KEYS; $i++) { $v = $arr['key-' . $i]; } } function fe(&$arr) { foreach ($arr as $key => $value) { $v = $value; } } ?> ---- Server IP: 87.124.126.137 Probable Submitter: 193.36.79.206 ---- Manual Page -- http://www.php.net/manual/en/class.arrayobject.php Edit -- https://master.php.net/note/edit/102747 Del: integrated -- https://master.php.net/note/delete/102747/integrated Del: useless -- https://master.php.net/note/delete/102747/useless Del: bad code -- https://master.php.net/note/delete/102747/bad+code Del: spam -- https://master.php.net/note/delete/102747/spam Del: non-english -- https://master.php.net/note/delete/102747/non-english Del: in docs -- https://master.php.net/note/delete/102747/in+docs Del: other reasons-- https://master.php.net/note/delete/102747 Reject -- https://master.php.net/note/reject/102747 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177525) next »