Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math: Int.ProbablyPrime is slow for even integers #9269

Closed
ALTree opened this issue Dec 11, 2014 · 1 comment
Closed

math: Int.ProbablyPrime is slow for even integers #9269

ALTree opened this issue Dec 11, 2014 · 1 comment

Comments

@ALTree
Copy link
Member

ALTree commented Dec 11, 2014

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
@ALTree
Copy link
Member Author

ALTree commented Dec 11, 2014

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants