PHP內建的Math函式效率測試

2022-10-06 11:24:13 字數 613 閱讀 5239

如題所示,對於沒有做過大規模運算的朋友來說,可能還不知道,php的math函式運算原來是如此之慢的,大家還是麻煩點,手寫多幾句,**如下:

複製** **如下:

$start = microtime(true);   

for ($i=0; $i < 200000; $i++)   程式設計客棧

}   

echo microtime(true) – $start;  // output: 0.33167719841003

再對比下用math函式的**和結果,**如下:

複製** **如下:

$start = microtime(true);   

for ($i=0; $i < 200000; $i++)

}echo microtime(true) – $start;   // output: 0.87528896331787

看到木有,效率提公升1程式設計客棧00%!!以前還一直都認為是php內建的math快,真是不測不知道,像取絕對值abs,最大值max,最小值min 等效率都不如原生的 if判斷來得快.

本文標題: php內建的math函式效率測試

本文位址: /wangluo/php/116642.html

PHP內建函式

獲取時間戳 時間戳是指自1970 01 01 00 00 00到現在這一瞬間的秒數。microtime true 常用於測試程式執行時間 start microtime true for i 1 i 1000 i end microtime true echo end start 時間戳格式化 ti...

多測師 Python(內建函式)

一.python內建函式 1.id 返回物件的記憶體位址 a 1 print id a print id 1 2.int 用於將資料型別轉換為整型 a 1 b 2 print int a b 3.str 用於將資料型別轉換為字串 age 18 name zhengying print name ag...

必須了解的PHP內建函式,開發效率提公升N倍

array filter array map array walk array reduce 用法和區別.有了他我們在開發中就不用去寫那麼多迴圈操作了,而且效率比迴圈取值更快。array filter 陣列 arr a 0,b c 1,2,3,4,5,6,7 過濾掉所有的數字,只要字串 減少自己迴圈...