[libmath-prime-util-perl] 02/55: Update precalc and timings

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:53:38 UTC 2015


This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.41
in repository libmath-prime-util-perl.

commit 3f94d58ae373c24b209d701b45df6a20d43c5f84
Author: Dana Jacobsen <dana at acm.org>
Date:   Wed Apr 23 14:34:46 2014 -0700

    Update precalc and timings
---
 examples/twin_primes.pl | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/examples/twin_primes.pl b/examples/twin_primes.pl
index 514cc70..65bb875 100755
--- a/examples/twin_primes.pl
+++ b/examples/twin_primes.pl
@@ -4,7 +4,7 @@ use warnings;
 
 use Math::Prime::Util qw/prime_iterator  prime_iterator_object
                          next_prime  is_prime
-                         nth_prime_upper  prime_precalc/;
+                         nth_prime_upper  nth_twin_prime_approx  prime_precalc/;
 
 my $count = shift || 20;
 
@@ -13,12 +13,12 @@ my $count = shift || 20;
 # Time for the first 300k:
 #
 # Not iterators:
-#   0.6s   forprimes { say $l if $l+2==$_; $l=$_; } 64764841
-#   1.0s   bin/primes.pl --twin 2 64764839
+#   0.5s   $l=2; forprimes { say $l if $l+2==$_; $l=$_; } 64764841
+#   0.8s   bin/primes.pl --twin 2 64764839
 #
 # Iterators with precalc:
-#   1.6s   get_twin_prime_iterator2
-#   2.4s   get_twin_prime_iterator1
+#   1.5s   get_twin_prime_iterator2
+#   2.3s   get_twin_prime_iterator1
 #   4.2s   get_twin_prime_iterator3
 #   4.5s   get_twin_prime_iterator4 (object iterator)
 #
@@ -29,10 +29,17 @@ my $count = shift || 20;
 #  16.7s   get_twin_prime_iterator4 (object iterator)
 #
 # Alternatives:
-# 251.9s   Math::NumSeq::TwinPrimes (Perl 5.19.7, Math::NumSeq 67)
+# 229.6s   Math::NumSeq::TwinPrimes (Perl 5.19.7, Math::NumSeq 69)
+#   6.6s - perl -MMath::PariInit=primes=65000000 -MMath::Pari=forprime,PARI -E
+#          '$l=2;forprime($x,2,64764841,sub{say $l if $l+2==$x;$l=int("$x");});' 
 
 # This speeds things up, but isn't necessary.
-my $estimate = 5000 + int( nth_prime_upper($count) * 1.4 * log($count) );
+#  Easy but estimates very high:
+#my $estimate = 5000 + int( nth_prime_upper($count) * 1.4 * log($count) );
+#  Relatively tight upper bound
+#my $estimate = 400 + int(1.01 * nth_twin_prime_approx($count));
+#  Simple and fastest:  Use the estimate directly.
+my $estimate = nth_twin_prime_approx($count);
 prime_precalc($estimate);
 
 # Create a twin prime iterator using the prime_iterator construct

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git



More information about the Pkg-perl-cvs-commits mailing list