Exercise caution when using the PHP built-in Math function _ PHP Tutorial

Source: Internet
Author: User
Use the built-in Math function of PHP with caution. The article details some of the usage procedures of PHP's built-in Math functions. I hope some methods will be helpful to you. As shown in the following figure... I do not know how to perform large-scale operations... The article details some of the usage procedures of PHP's built-in Math functions. I hope some methods will be helpful to you.

As shown in the following figure... I do not know how to perform large-scale operations... The Math function operation in PHP is so slow... You are still in trouble. you need to write a few more words in hand to calculate the number of birds ~~~

Xiao 'er! On the code ....

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 results of using the Math function

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

The efficiency is improved by 100%... I used to think it was PHP's built-in Math that was fast, but I don't know if I did .. Such as taking absolute abs, maximum max, and minimum min values is less efficient than native if to Judge faster ~~

In general, php operations are really slow ~~ It is really not suitable for large-scale algorithm operations ~~


Bytes. As shown in the following figure... I don't know how to perform large-scale operations on wood ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.