- microtime: documentation ( source)
- print_r: documentation ( source)
- call_user_func_array: documentation ( source)
<?php
// more info here: http://ro.php.net/manual/en/function.microtime.php
// and here: http://stackoverflow.com/questions/19973037/benchmark-memory-usage-in-php
// and an example here: http://3v4l.org/0ifv8
function benchmark(callable $function, $args=null, $count=1)
{
$time = microtime(TRUE);
for($i=0; $i<$count; $i++)
{
$result = is_array($args)?
call_user_func_array($function, $args):
call_user_func_array($function);
}
return array(
'total_time' => microtime(TRUE) - $time,
'average_time' => (microtime(TRUE) - $time)/$count,
'count' => $count
);
}
function p($string)
{
print_r($string . "<br>");
}
print( benchmark( p('t1'), array('test', 10) ) );