PHP 8.5.0 Alpha 1 available for testing

Voting

: max(two, nine)?
(Example: nine)

The Note You're Voting On

Nitrogen
9 years ago
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.

<< Back to user notes page

To Top