PHP Built-in math function efficiency test _php Tips

Source: Internet
Author: User
Tags php programming

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.

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.