Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparison QB64 compiled with gcc optimizations and without
#31
CRC-32 : I got this code from the site rosettacode. I added some code to test the processing speed with QB64 compiled with the O3 option and the original version.

6.7x seconds : program compiled with qb64 -O3
17.6x seconds : program compiled with original qb64

here the speed gain is clearly visible.

Code: (Select All)
' Rosetta Code -   CRC-32
Dim tab$(19)
tab$(0) = "malevolently malevolous malexecution malfeasance malfeasant malfeasantly malfeasants malfeasor overwon"
tab$(1) = "malfed malformation malformations malformed malfortune malfunction malfunctioned malfunctioning overwood"
tab$(2) = "malgovernment nonemotionalism nonemotionally verwing overwinning overwinter overwintered overwintering"
tab$(3) = "nonemanating nonemancipation nonemancipative nonembarkation nonembellished nonembellishing overwiped"
tab$(4) = "nonembellishment nonembezzlement nonembryonal nonembryonic nonembryonically nonemendable overwithered"
tab$(5) = "nonemendation nonemergence nonemergent nonemigrant nonemigration nonemission nonemotional overwomanize"
tab$(6) = "overwisdom overwise overwisely overwoman overwomanly overwooded overwoody overword overwords overwore"
tab$(7) = "overwork segreant segregable segregant segregate segregated segregatedly segregatedness segregateness"
tab$(8) = "segregates segregating segregation segregational segregationist segregationists segregative segregator"
tab$(9) = "teleostean teleostei teleosteous teleostomate teleostome teleostomi teleostomian teleostomous teleosts"
tab$(10) = "teleotemporal teleotrocha teleozoic teleozoon telepath telepathy telepathic telepathically telepathies"
tab$(11) = "telepathist telepathize nffroze unfibbed unfibbing unfiber unfibered unfibred unfibrous unfibrously"
tab$(12) = "unfickle unfictitious unfictitiously unfictitiousness unfidelity unfidgeting unfiducial unfielded"
tab$(13) = "unfiend unfiendlike unfierce unfiercely unfiery unfight unfightable unfighting unfigurable unfigured"
tab$(14) = "zulus zumatic zumbooruk zuni zunian zunyite zunis zupanate zurich zurlite zutugil zuurveldt zuza"
tab$(15) = "zwanziger zwieback zwiebacks zwieselite zwinglian zwinglianism zwinglianist zwitter zwitterion"
tab$(16) = "zwitterionic cognovits cogon cogonal cogons cogovernment cogovernor cogracious cograil cogrediency"
tab$(17) = "cogredient cogroad cogs cogswellia coguarantor coguardian cogue cogway cogways cogware cogweel"
tab$(18) = "cogweels cogwheel cogwheels xiphistna xiphisura xiphisuran xiphiura xiphius xiphocostal xiphodynia"
tab$(19) = "xiphodon xiphodontidae xiphoid xyphoid xiphoidal xiphoidian xiphoids xiphopagic xiphopagous xiphopagus"
Color 7: Print "Wait..."
Color 2: Print: Print " generation of test string..."
Dim tabch$(15)
For boucle% = 1 To 15
    chaine$ = ""
    For i = 1 To 10000
        chaine$ = chaine$ + tab$(Rnd * 19)
    Next i
    tabch$(boucle%) = chaine$
Next boucle%
Dim hash$(15)
Color 3: Print: Print " crc calculation 100 times in : ";
start = Timer(.001)
For nbr% = 1 To 100
    For boucle% = 1 To 15
        chaine$ = tabch$(boucle%)
        hash$(boucle%) = Hex$(crc32(chaine$))
    Next boucle%
Next nbr%
Print Timer(.001) - start; "seconds"
Color 14: Print
For boucle% = 1 To 15: Print " "; hash$(boucle%): Next boucle%
Color 7
End

Function crc32~& (buf As String)
    Static table(255) As _Unsigned Long
    Static have_table As _Byte
    Dim crc As _Unsigned Long, k As _Unsigned Long
    Dim i As Long, j As Long

    If have_table = 0 Then
        For i = 0 To 255
            k = i
            For j = 0 To 7
                If (k And 1) Then
                    k = _SHR(k, 1)
                    k = k Xor &HEDB88320
                Else
                    k = _SHR(k, 1)
                End If
                table(i) = k
            Next
        Next
        have_table = -1
    End If

    crc = Not crc ' crc = &Hffffffff

    For i = 1 To Len(buf)
        crc = (_SHR(crc, 8)) Xor table((crc And &HFF) Xor Asc(buf, i))
    Next

    crc32~& = Not crc
End Function
Reply


Messages In This Thread
RE: Comparison QB64 compiled with Ofast and without - by Coolman - 05-18-2022, 10:59 AM



Users browsing this thread: 7 Guest(s)