大家进来看了,仔细的看了,一定要看仔...
看到了吗?你们想起谁了。。。。 看什么??笨笨当然是看我的头...
- 娱乐乐园,
作者 nullfox 发布于 2003-09-01 分类:php基础编程
页面头部取一次microtime,结尾取一次microtime,两个相减得到页面执行时间。怎么得到的是7.30752944946E-05这样的值啊,如何转化为毫秒单位的?
演示:http://scriptcn.com/test/getruntime.php
代码:
[PHP]
<?php
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
$time_end = getmicrotime();
$runtime = $time_end - $time_start;
?>
页面执行时间:<?php echo $runtime?>
[/PHP]
逛论坛交流:求救:我这样计算页面执行时间对吗?
页面执行时间:0.0477999448776
没问题啊
加个round($runtime, 4);
限制下小数为数
这个结果是什么单位?毫秒?
试试这个行不行..
$result=substr($result,0,5); //$result为相减时间
谢谢Elliott 。这个行了。如果我要用second单位,该怎么写?
printf("页面执行时间:%1.4f",$runtime);
何解?我都胡涂啦
晕,我刚才还发了一贴,后来发现错了,我就改了,干脆我在改一下
to nullfox : $result=substr($result,0,5)."second";
to tmyu:朋友你有QQ吗?我想和你交个朋友!
有是有,只是不常用82986199
主要是我对函数的不熟悉,仔细学习了下,终于弄清楚了,谢谢楼上各位:-)
我用number_format行了,KnightE 的也行,substr($result,0,5)有问题的
演示:http://scriptcn.com/demo/php/GPT1.0/demo.php
http://scriptcn.com/demo/php/GPT1.0/GPT1.0_codestyle2/demo.php
10 条回复
回复