note 118398 added to function.gmp-strval
| From: | Nitrogen | Date: | Sun, 29 Nov 2015 23:56:32 +0000 |
| Subject: | note 118398 added to function.gmp-strval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204245@lists.php.net to get a copy of this message | ||
It may be worth noting that using gmp_strval can slow your script down a lot with large numbers.
This script for example, produces factorials in succession:
<?php
$start = microtime(TRUE);
$fact = gmp_init(1, 10);
for($i=1;$i<100000;$i++) { // calculates 100,000 factorials
$fact = gmp_mul($fact, $i); // $fact is now the result of the $ith factorial
// gmp_strval($fact, 10); // see below...
if(microtime(TRUE)-$start>1) // stop calculating after 1 second
break;
}
// print whatever result that took 1 second to complete
printf("\$i = %d\n\$fact = %s\n", gmp_strval($fact, 10));
?>
My server calculates around about the 69,500th factorial on average every time. Uncommenting that
gmp_strval line slows this process down dramatically, and only calculates about 5,000 factorials.
This is about 14 times longer than before (this is consistent with allowing it to run for any number
of seconds, not just 1).
Nitrogen.
----
Server IP: 72.52.91.14
Probable Submitter: 82.25.3.36
----
Manual Page -- http://php.net/manual/en/function.gmp-strval.php
Edit -- https://master.php.net/note/edit/118398
Del: integrated -- https://master.php.net/note/delete/118398/integrated
Del: useless -- https://master.php.net/note/delete/118398/useless
Del: bad code -- https://master.php.net/note/delete/118398/bad+code
Del: spam -- https://master.php.net/note/delete/118398/spam
Del: non-english -- https://master.php.net/note/delete/118398/non-english
Del: in docs -- https://master.php.net/note/delete/118398/in+docs
Del: other reasons-- https://master.php.net/note/delete/118398
Reject -- https://master.php.net/note/reject/118398
Search -- https://master.php.net/manage/user-notes.php