note 102728 deleted from class.arrayobject by danbrown
| From: | danbrown@php.net | Date: | Wed, 02 Mar 2011 15:44:05 +0000 |
| Subject: | note 102728 deleted from class.arrayobject by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177498@lists.php.net to get a copy of this message | ||
Note Submitter: schultz dot peter at hotmail dot com
----
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);
}
?>