- microtime: documentation ( source)
- print_r: documentation ( source)
- explode: documentation ( source)
- register_tick_function: documentation ( source)
<?php
function profile($dump = FALSE)
{
static $profile;
// Return the times stored in profile, then erase it
if ($dump) {
$temp = $profile;
unset($profile);
return ($temp);
}
$profile[] = microtime();
}
// Set up a tick handler
register_tick_function("profile");
// Initialize the function before the declare block
profile();
// Run a block of code, throw a tick every 2nd statement
declare(ticks=1) {
$data = 0;
++$data; //15
$data++; //15
$data+=1; //17
$data = $data + 1; //18
}
// Display the data stored in the profiler
$list = profile (TRUE);
$len = count($list);
print_r($list);
function getTime($time) {
list($usec, $sec) = explode(" ", $time);
return ((float)$usec + (float)$sec) * 1000000;
}
for ($i = 1; $i < $len; $i++) {
echo getTime($list[$i]) - getTime($list[$i - 1]), PHP_EOL;
}
//print_r(profile (TRUE));