在 CodeIgniter 中设置经过时间并更改小数位数

Setting elapsed time and changing the decimals in CodeIgniter

您可能知道基准 属性 中有一个名为 elapsed_time() 的函数。参数如下:

elapsed_time([$point1 = ''[, $point2 = ''[, $decimals = 4]]])

我正在尝试将值设置为值为 2 的第 3 个参数。这是我的简单代码:

echo $this->benchmark->elapsed_time('', '', 2);

但它仍然是 returns 默认值,小数点后面有四位小数。

你能告诉我为什么它不起作用吗?非常感谢你的帮助!非常感谢。

您需要设置基准,然后才能正常工作。在你的例子中没有起点也没有终点,因此第三个参数被忽略。

所以正确的用法是:

<?php $this->benchmark->mark('startpoint');?>
    //your code
<?php $this->benchmark->mark('endpoint');?>
<?php echo $this->benchmark->elapsed_time('startpoint', 'endpoint', 2);?>