我原本以为 gmp_fact() 比循环更有效,但测量结果却相反
<?php
$cislo = 112;
$fact = $cislo;
$ffact = 1;
$mt = microtime();
while($fact >= 1)
{
$ffact = $fact * $ffact;
$fact--;
}
$md=number_format(microtime()-$mt, 6);
echo "<h1>LOOP ($md):</h1>";
echo $ffact;
$mt = microtime();
$vec = gmp_fact($cislo);
$md=number_format(microtime()-$mt, 6);
echo "<h1>GMP FACT ($md):</h1>";
echo $vec;
exit();
?>
将输出
LOOP (0.000022s)
1.9745068572211E+182
GMP FACT (0.000132s)
1.9745068572211E+182
结果是 0.000022 秒循环,和 0.000132 秒 gmp_fact()