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
Project Euler-inspired primes-count algorithm. #89
Project Euler-inspired primes-count algorithm. #89
Conversation
Based on a solution to a PE problem which I found in a solved problem forum. Attributed to "Lucy Hedgehog". Works well for larger ranges. Benchmark: ``` [shlomif@localhost ~]$ LD_LIBRARY_PATH=~/apps/primesieve/lib64 /usr/bin/time ~/apps/primesieve/bin/primesieve -c1 $((10 ** 12 / 2)) $(( 10 ** 12)) 18299775876 4.83user 0.01system 0:04.85elapsed 99%CPU (0avgtext+0avgdata 18828maxresident)k 0inputs+0outputs (0major+6819minor)pagefaults 0swaps [shlomif@localhost ~]$ time primesieve -c1 $(( 10 ** 12 / 2)) $(( 10 ** 12 )) Sieve size = 128 KiB Threads = 8 100% Seconds: 31.459 Primes: 18299775876 primesieve -c1 $(( 10 ** 12 / 2)) $(( 10 ** 12 )) 249.77s user 0.23s system 794% cpu 31.462 total [shlomif@localhost ~]$ ```
Another benchmark:
|
Hi shlomif, Even though I don't fully understand your algorithm I think it is a combinatorial type prime counting algorithm based on Legendre's inclusion-exclusion formula. I am aware of that there are faster ways to count primes than the sieve of Eratosthenes (see here: https://github.com/kimwalisch/primecount#algorithms) for this reason I have created primecount (and also primesum). However in primesieve I really only want to include prime sieving algorithms. primesieve is already very complex (it is nearly 8000 lines of code) and it is difficult for myself to keep everything in my head when working on primesieve. If I would start adding optimized combinatorial type prime counting algorithms it would get extremely painful for myself to work on this project (and nobody else could possibly understand the code anymore). |
Thanks for the reply, @kimwalisch ! I'll give a more meaningful reply later. |
OK, here goes: first of all I should note that primecount is much faster here than Anyway, I think you are underestimating yourself and are fully capable of managing primesieve even if it gains more functionality. One of my projects ( https://github.com/shlomif/fc-solve ) has over 30,000 lines of C and C++ code in the production code directory, and 62,175 lines total there, whereas the repo contains 170,740 lines of code. And it is still manageable, and I recently found a way to improve the benchmark time by 10-20%. There are far larger open source and non-FOSS projects, and many are also manageable. Anyway, I think you should not compromise on what I call I see an unnecessarily slow Thanks! |
That's where our opinions differ. A large number of primesieve's users are interested in benchmarking their own fast sieve of Eratosthenes implementations against primesieve. If I would improve primesieve's counting implementation using the combinatorial prime counting algorithm this use case would not be possible anymore. Also I like the Unix philosophy: write programs that do one thing and do it well. For this reason primesieve only includes prime sieving algorithms and primecount includes combinatorial prime counting algorithms. |
Hi! I have a page that tries to debunk the And regarding that, primesieve already provides the |
Based on a solution to a PE problem which I found in a solved problem forum.
Attributed to "Lucy Hedgehog".
Works well for larger ranges. Benchmark: