首页 > 技术文章 > 测试php函数的执行时间

gelu 2018-10-15 20:34 原文

使用microtime() 可以将时间精确到秒之后4位,通过bcsub()避免获得科学计数法结果。

<?
function add($a, $b) {
    return $a + $b;
}

$start = microtime(true);


$result = add(99, 88888);

$end = microtime(true);
$usedTime = bcsub($end, $start, 4);

echo $usedTime;

推荐阅读