- microtime: documentation ( source)
<?php
$attempts = 100000;
$test = 1;
if ($test == 1) {
$start = microtime(true);
for ($i = 0; $i < $attempts; $i++) {
$user = array(
'id' => 27,
'name' => 'Pepe'
);
}
$end = microtime(true);
echo 'Array: ' . ($end - $start) . " <br />\n";
}
if ($test == 2) {
$start = microtime(true);
for ($i = 0; $i < $attempts; $i++) {
$user = new stdClass();
$user->id = 27;
$user->name = 'Pepe';
}
$end = microtime(true);
echo 'Object: ' . ($end - $start) . " <br />\n";
}
if ($test == 3) {
$start = microtime(true);
for ($i = 0; $i < $attempts; $i++) {
$user = (object) array(
'id' => 27,
'name' => 'Pepe'
);
}
$end = microtime(true);
echo 'Cast: ' . ($end - $start) . " <br />\n";
}