Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparison QB64 compiled with gcc optimizations and without
#21
Picture unroller. Author James D Jarvis. Found in the forum.

8.5x seconds : program compiled with qb64 -O3
8.5x seconds : program compiled with original qb64

Tested with an image with a resolution of 1024x768.

no gain with the use of _PutImage. surprising.
Code: (Select All)
' James D Jarvis : Picture unroller
img& = _LoadImage("pic3.jpg", 32) 'your image here
w = _Width(img&)
h = _Height(img&)
sc& = _NewImage(w, h, 32)
Screen sc&
_Delay 0.1
_ScreenMove _Middle
Cls: s = 3
start = Timer(.001)
For yc = 0 To h Step s:
    _Limit 30
    _PutImage (0, 0), img&, sc&, (0, 0)-(w, yc)
    _PutImage (0, yc - 6)-(w, yc + 6), img&, sc&, (0, yc)-(w, yc + 3)
Next yc
Print Timer(.001) - start; "seconds"
Reply
#22
hello Coolman
in this example _Limit 30 is the speed limiter/throttle, to decrease the runtime increase _Limit, try it with _Limit 40
Reply
#23
(05-09-2022, 05:50 PM)Coolman Wrote: Picture unroller. Author James D Jarvis. Found in the forum.

8.5x seconds : program compiled with qb64 -O3
8.5x seconds : program compiled with original qb64

Tested with an image with a resolution of 1024x768.

no gain with the use of _PutImage. surprising.
Code: (Select All)
' James D Jarvis : Picture unroller
img& = _LoadImage("pic3.jpg", 32) 'your image here
w = _Width(img&)
h = _Height(img&)
sc& = _NewImage(w, h, 32)
Screen sc&
_Delay 0.1
_ScreenMove _Middle
Cls: s = 3
start = Timer(.001)
For yc = 0 To h Step s:
    _Limit 30
    _PutImage (0, 0), img&, sc&, (0, 0)-(w, yc)
    _PutImage (0, yc - 6)-(w, yc + 6), img&, sc&, (0, yc)-(w, yc + 3)
Next yc
Print Timer(.001) - start; "seconds"


It should run at 8.5 seconds no matter what if _limit is governing a significant portion of the program which it is here. Your source image tested was 768 pixels high, the program shows that image in 3 pixel high bands 30 times a second which works out to 8.5333 seconds.
Reply
#24
thanks Jack. i came to the same conclusion. even with _Limit 40 it doesn't change anything. no speed gain. it seems that using _Limit distorts the result. the goal is to know if the _PutImage command is optimizable, I removed _Limit. it's too fast to compare, so I added a loop for a 10 times display.

Picture unroller. Author James D Jarvis. Found in the forum.

1.3x seconds : program compiled with qb64 -O3
2.5x program compiled with original qb64

this time the gain is visible.

Code: (Select All)
' James D Jarvis : Picture unroller
img& = _LoadImage("pic3.jpg", 32) 'your image here
w = _Width(img&)
h = _Height(img&)
sc& = _NewImage(w, h, 32)
Screen sc&
_Delay 0.1
_ScreenMove _Middle
Cls: s = 3
start = Timer(.001)
For boucle% = 1 To 10
    Cls
    For yc = 0 To h Step s
        _PutImage (0, 0), img&, sc&, (0, 0)-(w, yc)
        _PutImage (0, yc - 6)-(w, yc + 6), img&, sc&, (0, yc)-(w, yc + 3)
    Next yc
Next boucle%
Print Timer(.001) - start; "seconds"


Another example.

New screen - How ?. Found in the old forum.

1.4x seconds : program compiled with qb64 -O3
2.3x seconds : program compiled with original qb64

if you uncomment the line '_Limit 30, the gain will be zero. if you want to test, put 100 instead of 1000 in the loop.

Code: (Select All)
Screen1 = _NewImage(640, 480, 32)
Screen2 = _NewImage(640, 480, 32)
$Color:32
_Dest Screen1
Cls , Yellow
_PrintString (100, 240), "This is Screen 1"
_Dest Screen2
Cls , Red
_PrintString (340, 240), "This is Screen 2"
DefaultScreen = _NewImage(1300, 768, 32)
Screen DefaultScreen
_Delay 0.2
_ScreenMove _Middle
start = Timer(.001)
For boucle% = 1 To 1000
    _Dest Screen1
    Locate 3, 5: Print Time$ 'works on unvisible screen1 - print time$
    _Dest Screen2
    Circle (Rnd * 640, Rnd * 480), 10, _RGB32(255 * Rnd, 255 * Rnd, 255 * Rnd) 'works on unvisible Screen2 - draw circle
    _Dest 0 ' 0 is always visible SCREEN
    _PutImage (0, 0), Screen1, 0 'place first screen as image to visible screen
    _PutImage (1300 / 2, 0), Screen2, 0 'place second screen as imge to visible screen
    _Display
    '_Limit 30
Next boucle%
Print Timer(.001) - start; "seconds"
End
Reply
#25
thank you James D Jarvis. i missed your message. finally i removed the _LIMIT command and i got the answer i wanted.
Reply
#26
hello. i would like to test disk access by loading a large text file and manipulating it to do string searches. to do a speed comparison between the qb64 optimized O3 version and the original version. if you have a code. please post it.
Reply
#27
here is a very simple code that opens a text file of about 4 mo to read it line by line three times in a row with the use of Left$ InStr. the speed gain is not very important but it is always better with qb64 compiled with the -O3 option.

you need a text file of about 4 MB to test. i found the test file in the compressed archive Common Resource Files on this forum. you can find it here :

https://qb64phoenix.com/forum/showthread.php?tid=327

6.5x seconds : program compiled with qb64 -O3
7.2x seconds : program compiled with original qb64

Conclusion : disk accesses don't advantage much the version of qb64 compiled with the -O3 option. don't forget that modern operating systems use a disk cache in memory, which can distort the results.

Code: (Select All)
$Console
Screen 0
chaine$ = "": chaine2$ = ""
Open "370099 Word List.txt" For Input As #1
start = Timer(.001)
Color 7: Print "Wait..."
While EOF(1) = 0
    Line Input #1, chaine$
    chaine2$ = chaine$
Wend
Seek #1, 1
While EOF(1) = 0
    Line Input #1, chaine$
    If Left$(chaine$, 1) = "b" Then
        chaine2$ = chaine$
    End If
Wend
Seek #1, 1
While EOF(1) = 0
    Line Input #1, chaine$
    If InStr(1, chaine$, "oun") > 0 Then
        chaine2$ = chaine$
    End If
Wend
Color 3
Print: Print Timer(.001) - start; "seconds"
Color 7
Close #1
End
Reply
#28
here is a very simple code that opens a text file of about 4 mo to read it line by line and copy it to a new file. Here the speed gain is practically zero.

you need a text file of about 4 MB to test. i found the test file in the compressed archive Common Resource Files on this forum. you can find it here :

https://qb64phoenix.com/forum/showthread.php?tid=327

3.0x seconds : program compiled with qb64 -O3
3.0x seconds : program compiled with original qb64

Conclusion : in file reading and writing. no visible speed gain. don't forget that modern operating systems use a disk cache in memory, which can distort the results.

Code: (Select All)
$Console
Screen 0
start = Timer(.001)
Color 7: Print "Wait..."
Open "370099 Word List.txt" For Input As #1
Open "370099 Word List_output.txt" For Output As #2
Do
    Line Input #1, chaine$
    If EOF(1) Then
        Print #2, chaine$;
    Else
        Print #2, chaine$
    End If
Loop Until EOF(1)
Close #1
Close #2
Color 3: Print: Print Timer(.001) - start; "seconds"
Color 7
End
Reply
#29
here is another very simple code that copies a test file of about 4 mo to an array and copies the data randomly to another array.

you need a text file of about 4 MB to test. i found the test file in the compressed archive Common Resource Files on this forum. you can find it here :

https://qb64phoenix.com/forum/showthread.php?tid=327

program compiled with qb64 -O3

4.4x seconds : Read file and copy to table
7.1x seconds : Copy data randomly into another table.

program compiled with original qb64

5.9x seconds : Read file and copy to table
27.4x seconds : Copy data randomly into another table.

Code: (Select All)
$Console
Screen 0
Open "370099 Word List.txt" For Input As #1
Color 7: Print "Wait..."
compt = 0
start = Timer(.001)
chaine$ = ""
While EOF(1) = 0
    Line Input #1, chaine$
    compt = compt + 1
Wend
Color 2
Print: Print " "; compt; " : Number of lines in the file."
Seek #1, 1
chaine$ = "": compt2 = 0: Dim tab$(compt)
While EOF(1) = 0
    Line Input #1, chaine$
    compt2 = compt2 + 1
    tab$(compt2) = chaine$
Wend
Color 3
Print: Print " "; Timer(.001) - start; "seconds : Read file and copy to table."
Close #1
Dim tab2$(compt)
Randomize Timer
start = Timer(.001)
For i = 1 To compt
    tab2$(i) = tab$(Rnd * compt)
Next i
Color 2
Print: Print " "; Timer(.001) - start; "seconds : Copy data randomly into another table."
Color 7
End
Reply
#30
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

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
Reply




Users browsing this thread: 23 Guest(s)