[libmath-prime-util-perl] 114/181: use constant with hash. Saves a tiny bit of startup time
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:12 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.
commit 6b69260bc122f86e67323177407f2357c9a8bde7
Author: Dana Jacobsen <dana at acm.org>
Date: Sat Jan 4 03:05:55 2014 -0800
use constant with hash. Saves a tiny bit of startup time
---
lib/Math/Prime/Util.pm | 19 ++++++++++---------
lib/Math/Prime/Util/PP.pm | 20 ++++++++++++--------
xt/test-bpsw.pl | 4 ++--
3 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 26453f7..c8b410c 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -65,15 +65,16 @@ sub _import_nobigint {
BEGIN {
use Config;
- use constant OLD_PERL_VERSION => ($] < 5.008);
- use constant MPU_MAXBITS => 8 * $Config{uvsize};
- use constant MPU_64BIT => ($Config{uvsize} == 8);
- use constant MPU_32BIT => ($Config{uvsize} == 4);
- use constant MPU_MAXPARAM => ($Config{uvsize} == 4) ? 4294967295 : 18446744073709551615;
- use constant MPU_MAXDIGITS => ($Config{uvsize} == 4) ? 10 : 20;
- use constant MPU_MAXPRIME => ($Config{uvsize} == 4) ? 4294967291 : 18446744073709551557;
- use constant MPU_MAXPRIMEIDX => ($Config{uvsize} == 4) ? 203280221 : 425656284035217743;
- use constant UVPACKLET => ($Config{uvsize} == 8 ? 'Q' : 'L');
+ use constant { OLD_PERL_VERSION => ($] < 5.008),
+ MPU_MAXBITS => 8 * $Config{uvsize},
+ MPU_64BIT => ($Config{uvsize} == 8),
+ MPU_32BIT => ($Config{uvsize} == 4),
+ MPU_MAXPARAM => ($Config{uvsize} == 4) ? 4294967295 : 18446744073709551615,
+ MPU_MAXDIGITS => ($Config{uvsize} == 4) ? 10 : 20,
+ MPU_MAXPRIME => ($Config{uvsize} == 4) ? 4294967291 : 18446744073709551557,
+ MPU_MAXPRIMEIDX => ($Config{uvsize} == 4) ? 203280221 : 425656284035217743,
+ UVPACKLET => ($Config{uvsize} == 8 ? 'Q' : 'L'),
+ };
no Config;
# Load PP code. Nothing exported.
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 98ea9bd..8265f9d 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -19,12 +19,17 @@ BEGIN {
BEGIN {
use Config;
- use constant OLD_PERL_VERSION => ($] < 5.008);
- use constant MPU_MAXBITS => 8 * $Config{uvsize};
- use constant MPU_64BIT => ($Config{uvsize} == 8);
- use constant MPU_32BIT => ($Config{uvsize} == 4);
- use constant MPU_HALFWORD => ($Config{uvsize} == 4) ? 65536 : ($] < 5.008) ? 33554432 : 4294967296;
- use constant UVPACKLET => ($Config{uvsize} == 8 ? 'Q' : 'L');
+ use constant { OLD_PERL_VERSION => ($] < 5.008),
+ MPU_MAXBITS => 8 * $Config{uvsize},
+ MPU_64BIT => ($Config{uvsize} == 8),
+ MPU_32BIT => ($Config{uvsize} == 4),
+ #MPU_MAXPARAM => ($Config{uvsize} == 4) ? 4294967295 : 18446744073709551615,
+ #MPU_MAXDIGITS => ($Config{uvsize} == 4) ? 10 : 20,
+ #MPU_MAXPRIME => ($Config{uvsize} == 4) ? 4294967291 : 18446744073709551557,
+ MPU_MAXPRIMEIDX => ($Config{uvsize} == 4) ? 203280221 : 425656284035217743,
+ MPU_HALFWORD => ($Config{uvsize} == 4) ? 65536 : ($] < 5.008) ? 33554432 : 4294967296,
+ UVPACKLET => ($Config{uvsize} == 8 ? 'Q' : 'L'),
+ };
no Config;
}
@@ -795,8 +800,7 @@ sub nth_prime {
return $_primes_small[$n] if $n <= $#_primes_small;
- my $max = (MPU_32BIT) ? 203280221 : 425656284035217743;
- if ($n > $max && ref($n) ne 'Math::BigFloat') {
+ if ($n > MPU_MAXPRIMEIDX && ref($n) ne 'Math::BigFloat') {
do { require Math::BigFloat; Math::BigFloat->import(); }
if !defined $Math::BigFloat::VERSION;
$n = Math::BigFloat->new("$n")
diff --git a/xt/test-bpsw.pl b/xt/test-bpsw.pl
index 9f11a0c..e14ae35 100755
--- a/xt/test-bpsw.pl
+++ b/xt/test-bpsw.pl
@@ -121,7 +121,7 @@ print "Starting benchmarks, $num_rns $len_rns-digit random numbers...\n";
if (1) {
print "\nMiller-Rabin, one base:\n";
cmpthese($count, {
- "MPU:PP" => sub { Math::Prime::Util::PP::miller_rabin($_,2) for @rns; },
+ "MPU:PP" => sub { Math::Prime::Util::PP::is_strong_pseudoprime($_,2) for @rns; },
"MPU:GMP" => sub { Math::Prime::Util::GMP::is_strong_pseudoprime($_,2) for @rns; },
"MPU" => sub { Math::Prime::Util::is_strong_pseudoprime($_,2) for @rns; },
"MP" => sub { Math::Primality::is_strong_pseudoprime("$_","2") for @rns; },
@@ -142,7 +142,7 @@ if (1) {
print "\nBPSW test:\n";
cmpthese($count, {
"MPU:PP" => sub { my $sum = 0;
- do { $sum += ( Math::Prime::Util::PP::miller_rabin($_, 2) &&
+ do { $sum += ( Math::Prime::Util::PP::is_strong_pseudoprime($_, 2) &&
Math::Prime::Util::PP::is_strong_lucas_pseudoprime($_) )
? 1 : 0 } for @rns; },
"MPU:GMP" => sub { Math::Prime::Util::GMP::is_prob_prime($_) for @rns; },
--
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