PlummersSoftwareLLC / Primes

Prime Number Projects in C#/C++/Python
https://plummerssoftwarellc.github.io/PrimeView/
2.43k stars 574 forks source link

Inlined bit operations and moved sieve definition inside loop #912

Closed rzuckerm closed 1 year ago

rzuckerm commented 1 year ago

Description

For the both implementations, I moved the sieve definition inside the main prime loop to ensure that it keeps getting reallocation every iteration.

For the packed bit implementation (primes_bit.ex), I inlined the bit operations. This improved the speed by a factor of about 2.1x.

Contributing requirements

rbergen commented 1 year ago

@rzuckerm Thanks for submitting this. The changes themselves look good to me, but I did notice something else that I must have missed when I reviewed the version of the solution that's in the current codebase: you use the same label ("rzuckerm") in the drag-race output line for both implementations included in this solution. Could you please label each of them differently? It makes it easier to distinguish the implementations in the output of the automated benchmark runs (like shown in PrimeView, for example).

A very simple solution would be to change the one for the bit-level implementation to "rzuckerm-bit", but any other approach that leads to different labels would also be fine. I apologize for missing this before.

rzuckerm commented 1 year ago

@rbergen Done

rbergen commented 1 year ago

Thank you!