I have compared what I call Owen Deluxe 30 wheel to my original 30 wheel and find no significant difference in times.

Owen Deluxe 30 wheel

My original 30 wheel code:

My code steps the pcandidate by 2 in outer loop 15 times over 30 integers.

Owens deluxe code steps the pcandidate by a pattern amount 8 times over 30 integers.

You'd think that would save time but while stepping 1 time you increment a 2nd variable, the Pattern Index, one time and then check to see if that has reached 9 and to reset it to 1 if it did. I think that 2nd decision blows the time saved from doing less pcandidate steps.

Owen Deluxe 30 wheel

Code:

`' 30 wheel sieve Owen deluxe.bas for QB64 fork (B+=MGA) 2017-08-30 copy and trans to QB64`

'translated from: First Factors.bas for SmallBASIC 11/27/14 (bpf.org post)

'topN = 1000000, primes 78,498, .15 secs, 8169 twins last 999959, 999961

'topN = 10000000, primes 664,579, 1.81 secs, 58,980 twins last 9999971, 9999973

'topN = 100000000, primes 5,761,455, 19.65 secs, 440,312 twins last 99999587, 99999589

' out of memory for 1 billion

'compare to bigger wheel sieve WOW the 30 wheel is faster!

'QB64 results from 2310 wheel

'topN = 1000000, primes 78,498, .18 secs, 8169 twins last 999959, 999961

'topN = 10000000, primes 664,579, 1.98 secs, 58,980 twins last 9999971, 9999973

'topN = 100000000, primes 5,761,455, 21.57 secs, 440,312 twins last 99999587, 99999589

' out of memory for 1 billion

'Owen Deluxe 30 Wheel results

'topN = 1000000, primes 78498, .189 sec, 8169 twins

'topN = 10000000, primes 664,579, 1.797 secs, 58,980 twins

'topN = 100000000, primes 5,761,455, 20.45 sec, 440,312 twins

_DEFINE A-Z AS _INTEGER64

OPTION BASE 1

COMMON SHARED ff(), topN

topN = 1223 'first 200 primes test

topN = 100000000

testlimitN = SQR(topN)

'First Factors array, ff(index), is 0 if index is a prime number

' if index is composite then ff(index) contains the index's lowest factor

DIM ff(topN + 30)

tStart# = TIMER(.001)

FOR i = 0 TO topN STEP 30

ff(i + 2) = 2: ff(i + 3) = 3: ff(i + 4) = 2: ff(i + 5) = 5: ff(i + 6) = 2: ff(i + 8) = 2: ff(i + 9) = 3

ff(i + 10) = 2: ff(i + 12) = 2: ff(i + 14) = 2: ff(i + 15) = 3: ff(i + 16) = 2: ff(i + 18) = 2

ff(i + 20) = 2: ff(i + 21) = 3: ff(i + 22) = 2: ff(i + 24) = 2: ff(i + 25) = 5

ff(i + 26) = 2: ff(i + 27) = 3: ff(i + 28) = 2: ff(i + 30) = 2

NEXT

ff(2) = 0: ff(3) = 0: ff(5) = 0 'fix first 3 factors

pattern(1) = 4: pattern(2) = 2: pattern(3) = 4: pattern(4) = 2

pattern(5) = 4: pattern(6) = 6: pattern(7) = 2: pattern(8) = 6

pcand = 7

patternI = 0

WHILE pcand < testlimitN

IF ff(pcand) = 0 THEN

FOR i = pcand * pcand TO topN STEP 2 * pcand

IF ff(i) = 0 THEN ff(i) = pcand

NEXT

END IF

patternI = patternI + 1

IF patternI = 9 THEN patternI = 1

pcand = pcand + pattern(patternI)

WEND

'count primes

FOR i = 2 TO topN

IF ff(i) = 0 THEN p = p + 1

NEXT

tStop# = TIMER(.001)

tTime# = tStop# - tStart#

PRINT "For "; topN; " numbers there are "; p; " primes in "; tTime#; " secs."

My original 30 wheel code:

Code:

`' 30 wheel sieve.bas for QB64 fork (B+=MGA) 2017-08-30 copy and trans to QB64`

'translated from: First Factors.bas for SmallBASIC 11/27/14 (bpf.org post)

'topN = 1000000, primes 78,498, .15 secs, 8169 twins last 999959, 999961

'topN = 10000000, primes 664,579, 1.81 secs, 58,980 twins last 9999971, 9999973

'topN = 100000000, primes 5,761,455, 19.65 secs, 440,312 twins last 99999587, 99999589

' out of memory for 1 billion

'compare to bigger wheel sieve WOW the 30 wheel is faster!

'QB64 results from 2310 wheel

'topN = 1000000, primes 78,498, .18 secs, 8169 twins last 999959, 999961

'topN = 10000000, primes 664,579, 1.98 secs, 58,980 twins last 9999971, 9999973

'topN = 100000000, primes 5,761,455, 21.57 secs, 440,312 twins last 99999587, 99999589

' out of memory for 1 billion

_DEFINE A-Z AS _INTEGER64

OPTION BASE 1

COMMON SHARED ff(), topN

topN = 1223 'first 200 primes test

topN = 100000000

testlimitN = SQR(topN)

'First Factors array, ff(index), is 0 if index is a prime number

' if index is composite then ff(index) contains the index's lowest factor

DIM ff(topN + 30)

tStart# = TIMER(.001)

FOR i = 0 TO topN STEP 30

ff(i + 2) = 2: ff(i + 3) = 3: ff(i + 4) = 2: ff(i + 5) = 5: ff(i + 6) = 2: ff(i + 8) = 2: ff(i + 9) = 3

ff(i + 10) = 2: ff(i + 12) = 2: ff(i + 14) = 2: ff(i + 15) = 3: ff(i + 16) = 2: ff(i + 18) = 2

ff(i + 20) = 2: ff(i + 21) = 3: ff(i + 22) = 2: ff(i + 24) = 2: ff(i + 25) = 5

ff(i + 26) = 2: ff(i + 27) = 3: ff(i + 28) = 2: ff(i + 30) = 2

NEXT

ff(2) = 0: ff(3) = 0: ff(5) = 0 'fix first 3 factors

FOR pcand = 7 TO testlimitN STEP 2

IF ff(pcand) = 0 THEN

FOR i = pcand * pcand TO topN STEP 2 * pcand

IF ff(i) = 0 THEN ff(i) = pcand

NEXT

END IF

NEXT

'count primes

FOR i = 2 TO topN

IF ff(i) = 0 THEN p = p + 1

NEXT

tStop# = TIMER(.001)

tTime# = tStop# - tStart#

PRINT "For "; topN; " numbers there are "; p; " primes in "; tTime#; " secs."

My code steps the pcandidate by 2 in outer loop 15 times over 30 integers.

Owens deluxe code steps the pcandidate by a pattern amount 8 times over 30 integers.

You'd think that would save time but while stepping 1 time you increment a 2nd variable, the Pattern Index, one time and then check to see if that has reached 9 and to reset it to 1 if it did. I think that 2nd decision blows the time saved from doing less pcandidate steps.

B += x