05-13-2022, 06:34 PM
I found this code in the old forum apparently created by SMcNeill. Here, the interest is to see the difference in processing speed between the version of QB64 compiled in -O3 and the original version :
13.2x seconds : program compiled with qb64 -O3
26.2x seconds : program compiled with original qb64
13.2x seconds : program compiled with qb64 -O3
26.2x seconds : program compiled with original qb64
Code: (Select All)
Screen _NewImage(1280, 720, 32)
_Delay 0.2
_ScreenMove _Middle
Dim Shared Primes(1500000) As Long, count As Long
DefLng A-Z
Dim Shared Factors(10000000) As Long
Primes(0) = 2
Print "One moment.... finding primes"
start = Timer(.001)
For i = 3 To 1000000 Step 2
FindPrime (i)
Next
Print: Print "There are "; count; " numbers which are prime that can go into our numbers as factors"
Print
For i = 123456789 To 123456819
FindFactor (i)
Next
Print: Print "FINISHED IN "; Timer(.001) - start; "seconds"
End
Sub FindFactor (num)
Print num; "=";
Do
For i = 0 To count
p = Primes(i)
If p >= Sqr(num) Then Exit Do
If num Mod p = 0 Then 'it divides
Print p; "x";
num = num / p
Exit For
End If
Next
Loop Until num = 1
Print num
End Sub
Sub FindPrime (num)
For i = 0 To count
If num Mod Primes(i) = 0 Then Exit Sub
Next
count = count + 1
Primes(count) = num
End Sub