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

speed up prime(n) #102

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

speed up prime(n) #102

wants to merge 6 commits into from

Conversation

oscardssmith
Copy link
Member

87x faster for prime(10^7). There are still much better ways of computing this functions, but this is a fairly simple, but massive improvement.

@oscardssmith
Copy link
Member Author

oscardssmith commented Dec 10, 2021

The second commit here gives another 40% speedup by using a BitVector instead of Vector{Bool} Primes._primemask. This also gives a roughly 80% speedup in Primes._primemask which is considerable.

I was benchmarking wrong. It actually doesn't.

@oscardssmith oscardssmith changed the title speed up prime(n) speed up prime(n) WIP Dec 13, 2021
@oscardssmith oscardssmith mentioned this pull request Dec 13, 2021
@oscardssmith oscardssmith changed the title speed up prime(n) WIP speed up prime(n) Dec 19, 2021
@oscardssmith
Copy link
Member Author

@rfourquet this is ready to review (I just made it a bunch more complicated, sorry). The good news is that this is now 2000x faster than Master for prime(10^7) (14 seconds vs 7 ms). With this PR as it stands, prime(10^11) can be computed in 10.5 seconds on my computer. This is still not optimal, but is pretty good for only 100 lines of code. The biggest unfortunate thing about this PR in current state is that it adds SpecialFunctions as a dependency since it needs the Riemann Zeta function to estimate prime(n). If you think it would be better, I could turn this into a ccall to the MPFR function, which would keep this package as a lighter dependency.

@oscardssmith
Copy link
Member Author

@rfourquet one more question: How do you feel about making Primes.jl use multi-threading? Both this PR and #104 can be sped up more relatively via threading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant