note 47949 deleted from function.pow by victor
| From: | victor@php.net | Date: | Tue, 16 Aug 2005 12:04:40 +0000 |
| Subject: | note 47949 deleted from function.pow by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93728@lists.php.net to get a copy of this message | ||
Note Submitter: steemann at globalpark dot de
----
Just a note: the calculatepi function below can be speeded up a lot by skipping the pow function
call and by simplifying the addition term:
function calculatepi($terms)
{
$pi=0.0;
$k=1.0;
$j=1.0;
while ($terms--!=0)
{
$pi+=$j/$k;
$k+=2.0;
$j*=-1;
}
return 4.0*$pi;
}
Try this for 1,000,000 iterations and you'll see that the execution time is only about a third
of the version using pow printed below.
Of course, one could also use pi() or M_PI...