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

Switching between Sieving and Primality testing #85

Open
JASory opened this issue Nov 29, 2024 · 1 comment
Open

Switching between Sieving and Primality testing #85

JASory opened this issue Nov 29, 2024 · 1 comment

Comments

@JASory
Copy link
Contributor

JASory commented Nov 29, 2024

Sieving is particularly good at producing huge amounts of primes, particularly small ones and in sequential (or roughly sequential order). However their is some crossover point when the integers get large enough and the interval gets small enough that all the precomputation needed to sieve is slower than simply checking all the integers with a individual primality test.

From my comparisons of Machine-Prime and primesieve (the fastest primality testing and sieving software respectively), it seems that the crossover is around 100 million integers near 2^64 (i.e calling a fast primality test for less than 100 million integers around 2^64 is faster than sieving). I haven't benchmarked this program to see what the crossover point is but I suspect it is much higher and is something worth looking into. It would also save a considerable amount of memory.

@JSorngard
Copy link
Owner

JSorngard commented Nov 29, 2024

That is a very good point. If I understood you correctly something like sieve_geq should have a point for large enough lower_limit and small enough N where it is faster to just call is_prime on each of the numbers?

That makes a lot of sense. I'll make some benchmarks to try to find the crossover point for this library. Thank you so much for the insight!

Always going directly for using the primality test would make the API of those functions much nicer as well, but I think a combined approach could be made to work.

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

When branches are created from issues, their pull requests are automatically linked.

2 participants