Skip to content

Conversation

@GordonBGood
Copy link
Contributor

cabal generally installs packages with default -O1 optmization unless forced by a manual install - the recommended way to force it always to be installed with optimization is to add a "cabal.project" file with the high optimization specified as here.

Performance testing shows that the extra level of optimization gives a boost in execution speed of about two times, and for the prime counting function about two and a half times.

GordonBGood and others added 4 commits November 27, 2025 13:55
cabal generally installs packages with default -O1 optmization unless forced
by a manual install - the only way to force it always to be installed with
optimization is to add this to the cabal file.

Performance testing shows that the extra level of optimization gives a boost
in execution speed of about two times, and for the prime counting function
about two and a half times.
This version is more concise, simplified, and thereby faster at about
twice the speed of the old version for the same counting range and
optimization level; it would be about 100 lines of code without the
comments, but it is much better documented than the old version, also
including a "HowPrimeCountingWorks.md" file to give even more details.

This version does not call the Sieve of Eratosthenes (SoE) module, which
was part of the cruft in using that module when there wasn't much point;
the algorithm doesn't much depend for execution speed on SoE sieving and
this new version just implements a simple odds-only SoE within itself.

As specified, the module has been tested with GHC compiler versions
9.0.2, 9.2.8, 9.4.8, 9.6.7, 9.8.4, 9.10.2, and 9.12.2; version 14.1.0
was not tested because it is in the Release Candidate stage amd thus not
able to be installed through "ghcup".

I could not get it through the tests without hanging at toPrimeIntegral
Integer -> Int and don't know why it would change as it woudn't seem
counting primes would have anything to do with that, but the new version
has been tested extensively as to counting accuracy outside the testing
framework.
@GordonBGood
Copy link
Contributor Author

I screwed up and mistakenly PR'ed too many unintended commits together, including a broken new version of the prime count implementation module; I'm closing this PR, reverting the mistaken commits, and will resubmit a new PR with only the optimization improvements...

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

Successfully merging this pull request may close these issues.

1 participant