Skip to content

Instantly share code, notes, and snippets.

@huzemin
Created January 12, 2016 08:31
Show Gist options
  • Save huzemin/0f0c9e193d45af6e9217 to your computer and use it in GitHub Desktop.
Save huzemin/0f0c9e193d45af6e9217 to your computer and use it in GitHub Desktop.
Calculate what the function execute spend.
<?php
/**
* 计算函数的执行时间,可以用于性能统计
* @param $function
* @param array $params
* @param int $times
* @return mixed
*/
function cal_run_time($function, $params = array(), $times = 100) {
$_start = microtime(true);
for($i = 0; $i < $times; $i ++) {
call_user_func_array($function, $params);
}
$_end = microtime(true);
return $_end - $_start;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment