Took a quick poke, seems the prime? that prime-utils provides from a quick search is a Miller-Rabin test only guaranteed up to 25 digits?
I'm not sure if any of the num-prime's configurations match, but with the default configuration for is_prime() I get mildly better numbers than your earlier output of the first few values (this is on my somewhat dinky and outdated XPS 13+, so probably not particularly comparable):
5, 2, 1
Starting search for next Mp with known p = 5
Elapsed time = 281.2µs
7, 2, 2
Starting search for next Mp with known p = 7
Elapsed time = 298.3µs
13, 6, 4
Starting search for next Mp with known p = 13
Elapsed time = 259µs
17, 4, 5
Starting search for next Mp with known p = 17
Elapsed time = 243.5µs
19, 2, 6
Starting search for next Mp with known p = 19
Elapsed time = 165.4µs
31, 12, 9
Starting search for next Mp with known p = 31
Elapsed time = 129.2µs
61, 30, 16
Starting search for next Mp with known p = 61
Elapsed time = 175µs
89, 28, 22
Starting search for next Mp with known p = 89
Elapsed time = 793.2µs
107, 18, 26
Starting search for next Mp with known p = 107
Elapsed time = 302.1µs
127, 20, 29
Starting search for next Mp with known p = 127
Elapsed time = 256.9µs
521, 394, 96
Starting search for next Mp with known p = 521
Elapsed time = 8.0918ms
607, 86, 109
Starting search for next Mp with known p = 607
Elapsed time = 5.389ms
1279, 672, 205
Starting search for next Mp with known p = 1279
Elapsed time = 91.4553ms
2203, 924, 326
Starting search for next Mp with known p = 2203
Elapsed time = 539.6406ms
2281, 78, 337
Starting search for next Mp with known p = 2281
Elapsed time = 110.8559ms
3217, 936, 453
Starting search for next Mp with known p = 3217
Elapsed time = 2.0603048s
4253, 1036, 581
Starting search for next Mp with known p = 4253
Elapsed time = 5.2588387s
4423, 170, 600
Starting search for next Mp with known p = 4423
Elapsed time = 1.2408111s
9689, 5266, 1194
Starting search for next Mp with known p = 9689
Elapsed time = 202.7715133s
9941, 252, 1224
Starting search for next Mp with known p = 9941
Elapsed time = 25.4320905s
11213, 1272, 1355
Starting search for next Mp with known p = 11213
Elapsed time = 119.9335619s
Code in question:
use num_bigint::BigUint;
use num_prime::nt_funcs::is_prime;
use num_traits::Pow;
use std::time::Instant;
fn main() {
let mut p: BigUint = 3u32.into();
let mut m = 2u64;
let mut primes_tested = 0;
let mut tm = Instant::now();
loop {
let mut next_p = &p + m;
while !is_prime(&next_p, None).probably() {
m += 2;
next_p += 2u64;
}
primes_tested += 1;
// no BigUint: Shl<BigUint>
let mp = BigUint::from(2u32).pow(&next_p) - BigUint::ONE;
if is_prime(&mp, None).probably() {
p = next_p;
println!("{p}, {m}, {primes_tested}");
let next_tm = Instant::now();
println!("Starting search for next Mp with known p = {p}");
println!("Elapsed time = {:?}", next_tm - tm);
m = 2;
tm = next_tm;
} else {
m += 2;
}
}
}
num-prime does require an earlier num-bigint:
[package]
name = "mp"
version = "0.1.0"
edition = "2024"
[dependencies]
num-bigint = "0.4.8"
num-prime = "0.7.0"
num-traits = "0.2.19"