note 102728 added to class.arrayobject
| From: | schultz dot peter at hotmail dot com | Date: | Wed, 02 Mar 2011 15:43:13 +0000 |
| Subject: | note 102728 added to class.arrayobject | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177497@lists.php.net to get a copy of this message | ||
I was unable to reproduce skrebbel's benchmarks in PHP 5.3.0 on Fedora x86. My benchmarks
showed, that foreach iterations over ArrayObjects take about 160 to 175 % of the time of a foreach
iteration over an array, nowhere near 20000%. Maybe the performance was improved since
skrebbel's post, maybe one of our benchmarks was just badly written.
array fill : 0.236281
array read : 0.254270
array iterate : 0.023582
object fill : 0.221212
object read : 0.253145
object iterate : 0.040560
Code to reproduce:
<?php
require_once "Benchmark/Timer.php";
$bench = array();
$profile = array();
$timer = new Benchmark_Timer(true);
$recordBenchmark = function($stepName) use(&$profile, &$timer) {
$timer->setMarker($stepName);
$benchmark = end($timer->getProfiling());
$profile[$stepName] = $benchmark['diff'];
};
$benchSize = 100000;
foreach(array('array', 'object') as $type) {
$timer->setMarker('type benchmark start');
for ($i = 0; $i < $benchSize; $i++) {
$bench["-$i"] = "$i";
}
$recordBenchmark("$type fill");
for ($i = 0; $i < $benchSize; $i++) {
$dummy = $bench["$i"];
}
$recordBenchmark("$type read");
foreach($bench as $key => $value) {
}
$recordBenchmark("$type iterate");
$bench = new ArrayObject();
}
foreach($profile as $step => $time) {
printf("%-20s: %f\n", $step, $time);
}
?>
----
Server IP: 85.214.154.209
Probable Submitter: 92.206.34.53
----
Manual Page -- http://www.php.net/manual/en/class.arrayobject.php
Edit -- https://master.php.net/note/edit/102728
Del: integrated -- https://master.php.net/note/delete/102728/integrated
Del: useless -- https://master.php.net/note/delete/102728/useless
Del: bad code -- https://master.php.net/note/delete/102728/bad+code
Del: spam -- https://master.php.net/note/delete/102728/spam
Del: non-english -- https://master.php.net/note/delete/102728/non-english
Del: in docs -- https://master.php.net/note/delete/102728/in+docs
Del: other reasons-- https://master.php.net/note/delete/102728
Reject -- https://master.php.net/note/reject/102728
Search -- https://master.php.net/manage/user-notes.php