This article mainly introduces the built-in Math function efficiency test in PHP, tests the execution time of related PHP built-in mathematical functions in the form of examples, and analyzes the running efficiency, if you need it, you can refer to the example in this article to analyze the efficiency of the built-in Math function in PHP. Share it with you for your reference. The specific analysis is as follows:
As shown in the question, for friends who have not done large-scale operations, they may not know that the Math function operation in PHP is so slow. You still have to worry about writing a few more words, the code is as follows:
The code is as follows:
$ Start = microtime (TRUE );
For ($ I = 0; I 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
Then compare the code and result of using the Math function. the code is as follows:
The code is as follows:
$ Start = microtime (TRUE );
For ($ I = 0; I I <200000; $ I ++ ){
$ S = 0;
For ($ j = 0; $ j <3; $ j ++ ){
$ S + = pow ($ j + $ I + 1, 2 );
}
}
Echo microtime (TRUE)-$ start; // output: 0.87528896331787
As you can see, the efficiency is improved by 100% !! Previously, I always thought it was PHP's built-in Math speed, but I don't know if it was really unexpected. for example, taking the absolute value abs, the maximum value max, and the minimum value min is not as efficient as determining the native if condition.
In general, php operations are really slow and really not suitable for large-scale algorithm operations. I hope this article will help you with PHP programming.