mirror of
https://github.com/uutils/num-prime.git
synced 2026-06-10 16:12:35 -07:00
Minor fixes
This commit is contained in:
+13
-15
@@ -30,6 +30,13 @@ pub fn bench_is_prime(c: &mut Criterion) {
|
||||
.count()
|
||||
})
|
||||
});
|
||||
group.bench_function("number-theory", |b| {
|
||||
b.iter(|| {
|
||||
numbers()
|
||||
.filter(|&n| NumberTheory::is_prime(&n))
|
||||
.count()
|
||||
})
|
||||
});
|
||||
#[cfg(feature = "num-primes")]
|
||||
group.bench_function("num-primes", |b| {
|
||||
b.iter(|| {
|
||||
@@ -52,15 +59,6 @@ pub fn bench_is_prime(c: &mut Criterion) {
|
||||
.count()
|
||||
})
|
||||
});
|
||||
group.bench_function("number-theory", |b| {
|
||||
b.iter(|| {
|
||||
numbers()
|
||||
.filter(|&n| NumberTheory::is_prime(&n))
|
||||
.count()
|
||||
})
|
||||
});
|
||||
// TODO(v0.4.1): why is number-theory faster? difference in modular power?
|
||||
// we can add a markdown of performance after figuring out this
|
||||
|
||||
group.finish();
|
||||
|
||||
@@ -232,30 +230,30 @@ pub fn bench_prime_gen(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("prime generation (256 bits)");
|
||||
group.sample_size(10).sampling_mode(SamplingMode::Flat);
|
||||
|
||||
let mut gen = rand::thread_rng();
|
||||
let mut rng = rand::thread_rng();
|
||||
group.bench_function("num-prime (this crate)", |b| {
|
||||
b.iter(|| -> num_bigint::BigUint { gen.gen_prime(256, None) })
|
||||
b.iter(|| -> num_bigint::BigUint { rng.gen_prime(256, None) })
|
||||
});
|
||||
group.bench_function("num-primes", |b| {
|
||||
b.iter(|| Generator::new_prime(256))
|
||||
});
|
||||
group.bench_function("glass_pumpkin", |b| {
|
||||
b.iter(|| gprime::from_rng(256, &mut gen))
|
||||
b.iter(|| gprime::from_rng(256, &mut rng))
|
||||
});
|
||||
group.finish();
|
||||
|
||||
let mut group = c.benchmark_group("safe prime generation (256 bits)");
|
||||
group.sample_size(10).sampling_mode(SamplingMode::Flat);
|
||||
|
||||
let mut gen = rand::thread_rng();
|
||||
let mut rng = rand::thread_rng();
|
||||
group.bench_function("num-prime (this crate)", |b| {
|
||||
b.iter(|| -> num_bigint::BigUint { gen.gen_safe_prime(256) })
|
||||
b.iter(|| -> num_bigint::BigUint { rng.gen_safe_prime(256) })
|
||||
});
|
||||
group.bench_function("num-primes", |b| {
|
||||
b.iter(|| Generator::safe_prime(256))
|
||||
});
|
||||
group.bench_function("glass_pumpkin", |b| {
|
||||
b.iter(|| safe_gprime::from_rng(256, &mut gen))
|
||||
b.iter(|| safe_gprime::from_rng(256, &mut rng))
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ where
|
||||
for<'r> &'r T:
|
||||
RefNum<T> + std::ops::Shr<usize, Output = T> + ModularUnaryOps<&'r T, Output = T>,
|
||||
{
|
||||
#[inline]
|
||||
fn is_prp(&self, base: Self) -> bool {
|
||||
if self < &Self::one() {
|
||||
return false;
|
||||
@@ -136,6 +137,7 @@ where
|
||||
base.powm(&tm1, self).is_one()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_sprp(&self, base: Self) -> bool {
|
||||
self.test_sprp(base).either(|v| v, |_| false)
|
||||
}
|
||||
|
||||
+5
-2
@@ -80,6 +80,9 @@ impl BitOr<Primality> for Primality {
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
pub struct PrimalityTestConfig {
|
||||
// TODO: add option to divides small primes in the table
|
||||
// and this option should be enabled if the probabilistic test is used for strict config
|
||||
|
||||
/// Number of strong probable prime test, starting from base 2
|
||||
pub sprp_trials: usize,
|
||||
|
||||
@@ -98,8 +101,8 @@ impl Default for PrimalityTestConfig {
|
||||
/// composites with little computation
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
sprp_trials: 2,
|
||||
sprp_random_trials: 2,
|
||||
sprp_trials: 2, // test base 2 and 3
|
||||
sprp_random_trials: 3, // choose other 3 random bases
|
||||
slprp_test: false,
|
||||
eslprp_test: false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user