Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating Anti-Primes
#11
(07-07-2023, 08:15 PM)Stuart Wrote: @Space_Ghost

Just in case you're not aware of it, I'll mention that in the QB64 IDE under the "Options" menu, then "Compiler Settings" 

a page will be displayed where you can make changes that may (or may not) improve your program execution speed.

The first option : 
>> "Compile program with C++ optimization flag"
is what I'd try first -- (this is basically the same as using -O2 in the "C++ Compiler Flags" box.


Otherwise you could leave the option above unchecked and try the following values in the "C++ Compiler Flags" box.

-O2
-Os
-O3
(Note that this is the letter "O", not a zero.)

I personally find that -Os works better for me in a program that does a lot of repetitive math.

A more detailed description of these and more compiler options can be found here : 
https://doc.ecoscentric.com/gnutools/doc...tions.html

EDIT :
I just wanted to mention that each time the compiler options are changed the QB64 compiler files are purged and rebuilt which means that it will take longer to compile your program the first time, but after that it will take less time to compile (until the compiler settings are changed again).
Thank you Stuart.  This is very helpful!!  Greatly appeciated.
Cheers.
Reply
#12
Code: (Select All)
DefLng A-S
Dim p(20), k(250) As Integer
p(1) = 2: p(2) = 3: p(3) = 5: p(4) = 7: p(5) = 11: p(6) = 13: p(7) = 17: p(8) = 19: p(9) = 23: p(10) = 29
'yes these are primes
tt = Timer
Print "anti-prime, number of factors"
For i = 6 To 7000000 Step 2
    iq = i
    For j = 1 To 10
        k(j) = 0
        If p(j) > iq Then Exit For
        If iq = 1 Then Exit For
        Do Until (iq Mod p(j) <> 0)
            k(j) = k(j) + 1: iq = iq \ p(j)
        Loop
    Next j
    isum = 1
    For jk = 1 To j
        isum = (k(jk) + 1) * isum
    Next jk
    If isum > kmax Then
        Print i, isum
        kmax = isum
        knum = knum + 1
    End If
    k = 0
Next i
Print Timer - tt
Print knum + 3 'missed 1,2,4
Anti-primes have lots of small prime factors. So with that knowledge you can speed it up (a little)
Reply
#13
while I am an advocate for explicit variable declaration, your program David, runs almost 3 times faster with DefLng A-S than with option _explicit and Dim As Long i, iq, j, isum, jk, kmax, knum, k
Reply
#14
Strange! I've tried various assignments of the variables and DEFLNG A-S is the quickest. Maybe I have a very old version of QB64 (it says v2.0.2 at the bottom).
When I've got something that works I do not like to download newer versions as they often cause problems.
Reply
#15
David, I recommend that you try the latest QB64pe, you can always keep the older version
Reply
#16
Thanks David and Jack!  I really like your thoughts and code David.  Jack I did not know about the DEFLNG A-S vs. _EXPLICIT....good to know! 
Cheers
Reply
#17
Space_Gost
I don't know if it applies in general or for isolated examples, it did apply for David's example
Reply
#18
(07-08-2023, 04:39 PM)Jack Wrote: while I am an advocate for explicit variable declaration, your program David, runs almost 3 times faster with DefLng A-S than with option _explicit and Dim As Long i, iq, j, isum, jk, kmax, knum, k
I don't think that's the reason for the speed increase. A test with and without $Console already shows different times.
The results are peculiar. Without "Print knum" only half the time as with?
[Image: Anti-Prim-mit-Console2023-08-13.jpg]
[Image: Anti-Prim-ohne-Console2023-08-13.jpg]

[Image: Anti-Prim-mit-Console-Uwi2023-08-13.jpg]

[Image: Anti-Prim-mit-Console-Uwi-ohne-knum2023-08-13.jpg]
Reply




Users browsing this thread: 1 Guest(s)