Home  >  Article  >  Backend Development  >  Detailed explanation of php Math function

Detailed explanation of php Math function

怪我咯
怪我咯Original
2017-07-16 14:47:331761browse

Mathematics (Math) Function can handle values ​​in the range of integer and float.

This article mainly introduces PHP built-in Math function efficiency test, tests the execution time of related PHP built-in mathematical operation functions in the form of examples, and analyzes its For operational efficiency, friends who need it can refer to the

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

Then compare the code and results using the Math function, the code is 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

See that there is no , efficiency increased by 100%! ! I used to think that PHP's built-in Math was faster, but I didn't know it. The absolute value abs, the maximum value max, the minimum value min, etc. are not as efficient as the native if judgment.

The above is the detailed content of Detailed explanation of php Math function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn