- microtime: documentation ( source)
- range: documentation ( source)
- printf: documentation ( source)
<?php
$tests = array(
'$empty' => array(),
'$full' => range(1, 10),
);
$count = 10 * 1000 * 1000;
foreach ($tests as $name => $array) {
printf("%-10s", $name);
$start = microtime(true);
$i = $count;
while ($i-- > 0) {
(bool) $array;
}
$total = microtime(true) - $start;
printf("%.2F sec total, %.4F sec/iter\n", $total, $total / $count);
}