In this paper, we analyze the efficiency of math function built in PHP. Share to everyone for your reference. The specific analysis is as follows:
As the title shows, for a friend who has not done large-scale operations, may not know, PHP math function is so slow, we are still trouble point, handwriting more than a few words, the code is as follows:
Copy Code code as follows:
$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
In contrast, with the code and results of the math function, the code is as follows:
Copy Code code as follows:
$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
Saw the wood there, and the efficiency was elevated 100%!! has always been thought to be PHP built-in math fast, really rainy do not know, like absolute ABS, Max Max, Min min and other efficiency than the original if judgment came fast.
In general, the PHP operation is really slow, really not suitable for large-scale algorithm operations. I hope this article will help you with your PHP programming.