From 2c6cd90c1407c3d1961d622c5da97880fc5f821f Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Sun, 12 Jun 2022 22:48:56 +0800 Subject: faster gmp library in ch-2.pl --- challenge-168/steve-g-lynn/perl/ch-2.pl | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/challenge-168/steve-g-lynn/perl/ch-2.pl b/challenge-168/steve-g-lynn/perl/ch-2.pl index 0548ac1ebc..0e7ee4acf0 100755 --- a/challenge-168/steve-g-lynn/perl/ch-2.pl +++ b/challenge-168/steve-g-lynn/perl/ch-2.pl @@ -1,19 +1,14 @@ #!/usr/bin/perl #time (bash) output: -#real 0m0.026s -#user 0m0.019s -#sys 0m0.007s +#real 0m0.177s +#user 0m0.170s +#sys 0m0.006s -# but this fast time degrades sharply with larger problems -# -# real is 0m45.199s if home_prime(48) also printed -# real is 5m5.662s if home_prime of 48 and 65 also printed -# real is 8m50.059s if home_prime of 48, 65 and 96 also printed -# -# probably some slowdown in factor(.) for factors of very large primes -use Math::Prime::Util qw(is_prime factor); +use bigint; + +use Math::Prime::Util::GMP qw(is_prime factor); # very fast! print &home_prime(10),"\n"; #773 @@ -24,6 +19,16 @@ print &home_prime(16),"\n"; print &home_prime(20),"\n"; #3318308475676071413 +print &home_prime(48),"\n"; +#6161791591356884791277 + +print &home_prime(65),"\n"; +#1381321118321175157763339900357651 + +print &home_prime(96),"\n"; +#172929671097972226356946608292031596899264419 + + sub home_prime { my ($n)=@_; is_prime($n) && return $n; -- cgit