gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php Math函数详解

来源:http://erdangjiade.com/topic/1518.html 你好,世界。 2017-09-25 22:42浏览(11)

数学 (Math) 函数能处理 integer 和 float 范围内的值。

这篇文章主要介绍了PHP内置的Math函数效率测试,以实例形式测试了相关的PHP内置数学运算函数的执行时间,分析其运行效率,需要的朋友可以参考下

代码如下:

$start = microtime(TRUE);    
for ($i=0; $i < 200000; $i++){    
    $s = 0;
    for ($j=0; $j < 3; $j++){     
       $s += ($j+$i+1) * ($j+$i+1);
    }    
}    
echo microtime(TRUE) – $start;  // output: 0.33167719841003

再对比下用Math函数的代码和结果,代码如下:

$start = microtime(TRUE);    
for ($i=0; $i < 200000; $i++){
    $s = 0;
    for ($j=0; $j < 3; $j++){
       $s += pow($j+$i+1, 2);
    }
}
echo microtime(TRUE) – $start;   // output: 0.87528896331787

看到木有,效率提升100%!!以前还一直都认为是PHP内置的Math快,真是不测不知道,像取绝对值abs,最大值max,最小值min 等效率都不如原生的 if判断来得快.

以上就是php Math函数详解的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2