- hrtime: documentation ( source)
<?php
$x = [
"a" => 1,
"b" => "hello",
"c" => 5.5,
"d" => true,
];
$y = new stdClass();
$y->a = 1;
$y->b = "hello";
$y->c = 5.5;
$y->d = true;
$t1 = hrtime(true);
for ($i = 0; $i < 6000000; $i++) {
$a = $x["a"];
$b = $x["b"];
$c = $x["c"];
$d = $x["d"];
}
$t2 = hrtime(true);
$t3 = hrtime(true);
for ($i = 0; $i < 6000000; $i++) {
$a = $y->a;
$b = $y->b;
$c = $y->c;
$d = $y->d;
}
$t4 = hrtime(true);
echo "With array : " . (($t2 - $t1) / 1000000) . " ms\n";
echo "With object: " . (($t4 - $t3) / 1000000) . " ms\n";
class A
{
public $a;
public $b;
public $c;
public $d;
}