- Output for 8.3.8
- With class: 0.00036883354187012 With array: 0.00033283233642578 With converted stdClass: 0.00039887428283691
<?php
echo 'With class: ';
$start_time = microtime(TRUE);
class Data {
public $foo = 'example';
public $bar = 'example';
}
$data = new Data();
for ($i = 0; $i < 10000; $i++) {
$prop = 'foo';
$data->$prop; // access property but no echo, just to not polute the output;
}
$end_time = microtime(TRUE);
echo $end_time - $start_time . "\n";
echo "With array: ";
$start_time = microtime(TRUE);
$data = [
'foo' => 'example',
'bar' => 'example',
];
for ($i = 0; $i < 10000; $i++) {
$prop = 'foo';
$data[$prop]; // access key but no echo, just to not polute the output;
}
$end_time = microtime(TRUE);
echo $end_time - $start_time . "\n";
echo "With converted stdClass: ";
$start_time = microtime(TRUE);
$data = (object) [
'foo' => 'example',
'bar' => 'example',
];
for ($i = 0; $i < 10000; $i++) {
$prop = 'foo';
$data->$prop; // access propery but no echo, just to not polute the output;
}
$end_time = microtime(TRUE);
echo $end_time - $start_time;