Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparison QB64 compiled with gcc optimizations and without
#11
if these options exist, it is well to be used. the gain of speed of the programs is very important with freebasic less with qb64. it is strange. it is necessary to make more test to see if it is interesting with qb64. if you have intensive algorithms of calculations, that interests me. here is another example.

after converting the copy of the old forum unfortunately not complete in pdf format. then in text format. i assembled all the files in a single text file of about 200 mo. i have access to a lot of data on qb64. i found a fast sorting algorithm created by Phlashlite.

I lightened the code a bit.

sorting algorithm QuickSort.

4.4x seconds : program compiled with qb64 -Ofast
4.6x seconds : program compiled with original qb64

the gain is negligible. it is not very efficient for sorting algorithms as in the previous example.

Code: (Select All)
_Title "QuickSort Demo"
Screen _NewImage(640, 480, 32)
Const ARRAY_SIZE = 10000000
Dim Shared DemoArray(ARRAY_SIZE)
Print: Print
start = Timer
For i = 0 To ARRAY_SIZE
    DemoArray(i) = Int(Rnd * 255)
Next
Print " generation of an array of"; Str$(ARRAY_SIZE); " elements performed in"; Timer - start; "seconds":
'==============================================================================
Dim Shared ArrayLength
ArrayLength = ARRAY_LENGTH(DemoArray())
Print: Print
start = Timer
QuickSort 0, ARRAY_SIZE - 1, DemoArray()
Print Str$(ARRAY_SIZE); " members sorted in"; Timer - start; "seconds"
'==============================================================================
Sleep

Sub QuickSort (start, finish, array())
    'Straight from the QB64 wiki
    Dim Hi, Lo, Middle
    Hi = finish
    Lo = start
    Middle = array((Lo + Hi) / 2) 'find middle of array
    Do
        Do While array(Lo) < Middle
            Lo = Lo + 1
        Loop
        Do While array(Hi) > Middle
            Hi = Hi - 1
        Loop
        If Lo <= Hi Then
            Swap array(Lo), array(Hi)
            Lo = Lo + 1
            Hi = Hi - 1
        End If
    Loop Until Lo > Hi
    If Hi > start Then Call QuickSort(start, Hi, array())
    If Lo < finish Then Call QuickSort(Lo, finish, array())
End Sub
'______________________________________________________________________________
'Find the largest member of an array set.
Function ARRAY_MAX_VALUE (Array(), ArrayLength)
    For i = 0 To ArrayLength
        If Array(i) > tmx% Then tmx% = Array(i)
    Next
    ARRAY_MAX_VALUE = tmx%
End Function
'______________________________________________________________________________
'Calculate the size of an array.
Function ARRAY_LENGTH (Array())
    ARRAY_LENGTH = UBound(Array) - LBound(Array)
End Function
Reply


Messages In This Thread
RE: Comparison QB64 compiled with Ofast and without - by Coolman - 05-08-2022, 09:55 AM



Users browsing this thread: 38 Guest(s)