计算 PHP 脚本执行时间的 PHP 程序
要计算 PHP 脚本的执行时间,代码如下 −
示例
<?php
$start = microtime(true);
$val=1;
for($i = 1; $i <=1500; $i++)
{
$val++;
}
$end = microtime(true);
$exec_time = ($end - $start);
echo "The execution time of the PHP script is : ".$exec_time." sec";
?>输出
The execution time of the PHP script is : 1.69 sec
‘Microtime’ 函数可用于检查 PHP 脚本执行完成所花费的时间。当代码开始执行时,记录时间,代码完成后,生成另一个时间戳,结束时间和开始时间之间的差值就是脚本完成其执行所花费的时间。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP