php计算函数执行时间的方法
作者:work24 时间:2023-09-29 12:37:19
本文实例讲述了php计算函数执行时间的方法。分享给大家供大家参考。具体如下:
我们可以通过在程序的前后分别记录开始和结束时间,两个时间差就是程序的执行时间。
<?php
$long_str = "this is a test to see how much time md5 function takes to execute over this string";
// start timing from here
$start = microtime(true);
// function to test
$md5 = md5($long_str);
$elapsed = microtime(true) - $start;
echo "That took $elapsed seconds.\n";
?>
运行结果如下:
That took 7.1525573730469E-6 seconds.
php 计算函数执行时间的方法及获得微妙的方法
// 获得微妙方法
function getMillisecond()
{
list($s1, $s2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
原理:分别记录函数开始时间和结束时间,然后时间差就是函数执行的时间
<?php
$start_time = microtime(true);
for($i=1;$i<=1000;$i++){
echo $i.'<br>';
}
$end_time = microtime(true);
echo '循环执行时间为:'.($end_time-$start_time).' s';
?>
希望本文所述对大家的php程序设计有所帮助。
标签:php,执行,时间
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈解决360兼容模式浏览器的方法
2023-09-17 01:11:39
python+opencv实现霍夫变换检测直线
2021-07-30 04:08:57
![](https://img.aspxhome.com/file/2023/1/89351_0s.jpg)
MySQL字符编码设置方法
2024-01-21 07:52:51
MySQL数据库8——数据库中函数的应用详解
2024-01-23 18:18:07
![](https://img.aspxhome.com/file/2023/4/129914_0s.png)
javascript获取select标签选中的值
2024-05-09 10:34:41
MYSQL初学者命令行使用指南
2024-01-15 08:46:33
![](https://img.aspxhome.com/file/2023/0/102380_0s.jpg)
Python编写带选项的命令行程序方法
2023-11-18 20:47:35
python实现基于朴素贝叶斯的垃圾分类算法
2021-01-18 16:46:06
![](https://img.aspxhome.com/file/2023/8/134478_0s.jpg)
实践Python的爬虫框架Scrapy来抓取豆瓣电影TOP250
2021-04-26 21:27:11
![](https://img.aspxhome.com/file/2023/1/110391_0s.jpg)
python使用chardet判断字符串编码的方法
2023-02-02 06:45:20
详解在Python程序中自定义异常的方法
2021-05-17 00:34:28
python队列Queue的详解
2022-10-09 16:56:21
MySQL并发更新数据时的处理方法
2024-01-21 13:57:00
![](https://img.aspxhome.com/file/2023/9/71049_0s.jpg)
Python实现的删除重复文件或图片功能示例【去重】
2023-12-25 00:49:07
![](https://img.aspxhome.com/file/2023/6/102846_0s.png)
python中实现延时回调普通函数示例代码
2023-10-03 02:17:04
Python的迭代器和生成器
2022-04-29 17:56:09
python实现棋盘覆盖问题及可视化
2021-04-17 02:10:29
![](https://img.aspxhome.com/file/2023/2/118412_0s.png)
用CSS3将你的设计带入下个高度[译]
2009-06-22 13:03:00
![](https://img.aspxhome.com/file/UploadPic/20096/22/01-62s.jpg)
分享216色网页拾色器(调色板)
2007-09-27 12:33:00
![](https://img.aspxhome.com/file/UploadPic/20079/27/2007927124954557s.jpg)
python实现备份目录的方法
2022-10-30 02:54:04