简单检测PHP运行效率脚本
<?php $stratTime = microtime(true); $startMemory = memory_get_usage(); $a = 1; for($i = 1; $i <= 100000; $i++){ $a++; } echo $a; $endTime = microtime(true); $runtime = ($endTime - $stratTime) * 1000; //将时间转换为毫秒 $endMemory = memory_get_usage(); $usedMemory = ($endMemory - $startMemory) / 1024; echo "运行时间: {$runtime} 毫秒<br />"; echo "耗费内存: {$usedMemory} K";
运行情况
100001运行时间: 3 - 7 毫秒
耗费内存: 0.109375 K