Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

An improved version Sieve32FastV2Sieve32FastV2 is available.

I don’t consider the code to be complicated but is quite a bit longer than a simple sieve. If a simple sieve is more of your speed, stick with Sieve31Sieve31 or Sieve32Sieve32.

Sieve31Sieve31 a simple sieve for 31 bit primes, or int. Uses BitArray. Likely candidate for ToList().

Sieve32Sieve32 a simple sieve for 32 bit primes, or uint. Uses BitArray. Due to memory needs, a bool[] version is not possible.

EBrown’s answerEBrown’s answer to Sieve31. Uses a bool[]. Over 40% faster than Sieve31 but uses 600% the memory. Due to memory constraints, cannot use ToList().

The version below is as fast if not faster than EBrown’s answerEBrown’s answer (depends on number of cores) but requires only 4% more memory than Sieve31.

  • Sieve32Sieve32 took 77.10 seconds and used 283 MB memory.
  • Sieve32Fast above took 41.23 seconds and used 293 MB memory.

An improved version Sieve32FastV2 is available.

I don’t consider the code to be complicated but is quite a bit longer than a simple sieve. If a simple sieve is more of your speed, stick with Sieve31 or Sieve32.

Sieve31 a simple sieve for 31 bit primes, or int. Uses BitArray. Likely candidate for ToList().

Sieve32 a simple sieve for 32 bit primes, or uint. Uses BitArray. Due to memory needs, a bool[] version is not possible.

EBrown’s answer to Sieve31. Uses a bool[]. Over 40% faster than Sieve31 but uses 600% the memory. Due to memory constraints, cannot use ToList().

The version below is as fast if not faster than EBrown’s answer (depends on number of cores) but requires only 4% more memory than Sieve31.

  • Sieve31 took 37.97 seconds and used 143 MB memory.

  • EBrown’s answer took 22.18 seconds and used 1 GB memory.

  • Sieve32Fast above took 20.38 seconds and used 149 MB.

  • Sieve32 took 77.10 seconds and used 283 MB memory.
  • Sieve32Fast above took 41.23 seconds and used 293 MB memory.

An improved version Sieve32FastV2 is available.

I don’t consider the code to be complicated but is quite a bit longer than a simple sieve. If a simple sieve is more of your speed, stick with Sieve31 or Sieve32.

Sieve31 a simple sieve for 31 bit primes, or int. Uses BitArray. Likely candidate for ToList().

Sieve32 a simple sieve for 32 bit primes, or uint. Uses BitArray. Due to memory needs, a bool[] version is not possible.

EBrown’s answer to Sieve31. Uses a bool[]. Over 40% faster than Sieve31 but uses 600% the memory. Due to memory constraints, cannot use ToList().

The version below is as fast if not faster than EBrown’s answer (depends on number of cores) but requires only 4% more memory than Sieve31.

  • Sieve31 took 37.97 seconds and used 143 MB memory.

  • EBrown’s answer took 22.18 seconds and used 1 GB memory.

  • Sieve32Fast above took 20.38 seconds and used 149 MB.

  • Sieve32 took 77.10 seconds and used 283 MB memory.
  • Sieve32Fast above took 41.23 seconds and used 293 MB memory.
added link to Version 2
Source Link
Rick Davin
  • 6.4k
  • 1
  • 19
  • 31

An improved version Sieve32FastV2 is available.

An improved version Sieve32FastV2 is available.

Removed backticks from code which was already formatted in a block;
Source Link
Der Kommissar
  • 20.1k
  • 4
  • 68
  • 158
`varvar prime32 = ToNumber(bitIndex, rootVector.StartingNumber);`;
`var prime32 = ToNumber(bitIndex, rootVector.StartingNumber);`
var prime32 = ToNumber(bitIndex, rootVector.StartingNumber);
added 6 characters in body; edited title
Source Link
Ethan Bierlein
  • 15.8k
  • 4
  • 59
  • 146
Loading
Source Link
Rick Davin
  • 6.4k
  • 1
  • 19
  • 31
Loading