php计算代码运行时间与内存使用的一段代码

计算运行时间及内存使用,代码如下:

<?php
//开始计时
$HeaderTime = microtime(true);//参数true表示返回浮点数值

//代码

//...

printf(" total run: %.2f s<br>".
"memory usage: %.2f M<br> ",
microtime(true)-$HeaderTime,
memory_get_usage() / 1024 / 1024 );
?>

结果:

total runtime: 1.47 s

memory usage: 77.09 M

原文地址:https://www.cnblogs.com/study100/p/3190035.html