-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
The ProbablyPrime function in math/big filters out multiples of small odd primes before performing the Miller-Rabin rounds.. but it doesn't check for parity if the tested number is bigger than a word.
This leads to odd performances:
func BenchmarkPP2(b *testing.B) {
// 521419622856657689423872613771 * 2
n := new(big.Int)
n.SetString("1042839245713315378847745227542", 10)
for i := 0; i < b.N; i++ {
dummy = n.ProbablyPrime(30)
}
}
func BenchmarkPP3(b *testing.B) {
// 521419622856657689423872613771 * 3
n := new(big.Int)
n.SetString("1564258868569973068271617841313", 10)
for i := 0; i < b.N; i++ {
dummy = n.ProbablyPrime(30)
}
}
Gives
PASS
BenchmarkPP2 5000 373102 ns/op
BenchmarkPP3 1000000 1322 ns/op