CI框架源码完全分析之核心文件(基准测试类)Benchmark.php
CI框架中基准测试类Benchmark.php,它是计算任意两个标记点的时间差。
marker[$name] = microtime();
}
/**
*计算任意两个点之间的运行时间
*/
function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
{
if ($point1 == '')
{
return '{elapsed_time}';
}
if ( ! isset($this->marker[$point1]))
{
return '';
}
if ( ! isset($this->marker[$point2]))
{
$this->marker[$point2] = microtime();
}
//使用list()也是必然,因为microtime()函数返回的是以 "msec sec" 的格式返回一个字符串即微秒数和秒数,用空格分隔
list($sm, $ss) = explode(' ', $this->marker[$point1]);
list($em, $es) = explode(' ', $this->marker[$point2]);
return number_format(($em + $es) - ($sm + $ss), $decimals);
}
function memory_usage()
{
return '{memory_usage}';
}
}
你完全可以将这个Benchmark以后用到自己的程序中测试PHP性能。
PHP之友评论