Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#11
OK now I checked with $Checking :OFF

and found I had the < wrong when fcirc had finally beat FC2 once!

So I got 7 FC2, 1 fcir and 2 ties.

Code: (Select All)
_Title "FC2 edges out fcirc" ' b+ 2024-08-28
'Dav, AUG/2024 bplus mod 2024-08-28  try faster FC2 mod of fc

'fc & fcirc circle fill test.
'testing two filled circle SUB's for the fastest one.
'draws 100,000 circles and compares speed.

'fcirc still reigns as fastest on my laptop, by a little.
$Checking:Off
Screen _NewImage(1000, 700, 32)
_ScreenMove 150, 0
Randomize Timer
Print "Overlapping lines check of FC2"
FC2 500, 350, 300, &H200000FF ' check for overlapping lines
Print "Looking good! no lighter lines." ' FC passes too BTW
Print: Print " zzz... press any for timed test"
Sleep

'time the fc sub
t# = Timer
For c = 1 To 200000
    fcirc Rnd * _Width, Rnd * _Height, 35, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
Next
t1# = Timer - t#

'time the fc2 sub
t# = Timer
For c = 1 To 200000
    FC2 Rnd * _Width, Rnd * _Height, 35, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
Next
t2# = Timer - t#

Print
Print "fcirc ="; t1#
Print "  FC2 ="; t2#
Print

If t2# < t1# Then
    Print "FC2 wins!"
ElseIf t1# < t2# Then ' EDIT fixed!
    Print "fcirc wins!"
Else
    Print "Tie fcirc = FC2 time"
End If

Sub fc (cx, cy, r, clr&)
    For y = -r To r
        x = Int(Sqr(r * r - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
    Next
End Sub

Sub FC2 (cx, cy, r, clr&)
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    y = 1
    While y <= r
        x = Int(Sqr(r * r - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        y = y + 1
    Wend
End Sub


Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

BTW I am running v3.13 and I am wondering if earlier versions would give these results.
b = b + ...
Reply
#12
Hey, neat mod!  I thought it may be a little faster putting the r * r outside of the loop, and it made it FC2 a wee bit faster

EDIT:  (most of the time, FC3 ties FC2 now and then).

- Dav

Code: (Select All)
Sub FC3 (cx, cy, r, clr&)
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    y = 1
    r2 = r * r
    While y <= r
        x = Int(Sqr(r2 - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        y = y + 1
    Wend
End Sub

Find my programs here in Dav's QB64 Corner
Reply
#13
(08-28-2024, 12:30 PM)Dav Wrote: Hey, neat mod!  I thought it may be a little faster putting the r * r outside of the loop, and it made FC2 a wee bit faster.

- Dav

Code: (Select All)
Sub FC3 (cx, cy, r, clr&)
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    y = 1
    r2 = r * r
    While y <= r
        x = Int(Sqr(r2 - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        y = y + 1
    Wend
End Sub

+1 Yeah! one less calculation!

I just tested 10 runs on QB64 v 2.1 and the results are upside down!

7 wins for fcirc, 2 wins for FC2 and 1 tie!

Plus the times are less!!! (This is with checking off still).

Did you guys (developers) break something?
b = b + ...
Reply
#14
Update: I thought might be advantage to smaller circles but no!

And QB64 v2.1 does run this code significantly faster!

Bigger circles all on screen
Code: (Select All)
_Title "FC3 versus fcirc QB64pe v3.13.1" ' b+ 2024-08-29
'Dav, AUG/2024 bplus mod 2024-08-28  try faster FC2 mod of fc

' 2024-08-29 try larger circles all on screen with FC3
$Checking:Off
Screen _NewImage(1000, 700, 32)
_ScreenMove 150, 0
Randomize Timer
Print "Overlapping lines check of FC2"
FC3 500, 350, 300, &H200000FF ' check for overlapping lines
Print "Looking good! no lighter lines." ' FC passes too BTW
Print: Print " zzz... press any for timed test"
Sleep
Cls
For i = 1 To 10 ' in case going first has disadvantage
    'time the fc sub
    t# = Timer
    For c = 1 To 2000
        fcirc Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        '_Display
    Next
    t1# = t1# + Timer - t#

    'time the fc2 sub
    t# = Timer
    For c = 1 To 2000
        FC3 Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        ' _Display
    Next
    t2# = t2# + Timer - t#
Next
Print
Print "fcirc ="; t1#
Print "  FC3 ="; t2#
Print

If t2# < t1# Then
    Print "FC3 wins!"
ElseIf t1# < t2# Then ' EDIT fixed!
    Print "fcirc wins!"
Else
    Print "Tie fcirc = FC3 time"
End If
'_Display
Sub fc (cx, cy, r, clr&)
    For y = -r To r
        x = Int(Sqr(r * r - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
    Next
End Sub

Sub FC3 (cx, cy, r, clr&)
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    y = 1
    r2 = r * r ' Dav mod
    While y <= r
        x = Int(Sqr(r2 - y * y)) ' r2 Dav
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        y = y + 1
    Wend
End Sub


Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

   
b = b + ...
Reply
#15
Holy hell what is going on with QB64pe v 3.4.1 ???

   

   

Any body else still have version QB64pe v 3.4.1 ?
b = b + ...
Reply
#16
Ah compiler options! The top X makes a difference
   
b = b + ...
Reply
#17
OK I started using _Display because I didn't like seeing all those incomplete circles drawn and at first it looked like fcirc was going to win everytime. _Display definitely slowed everything down considerable. I had switched to declared Types for the FC3 sub because I thought the optimized compiler would love that!

I thought wrong! FC3 sub beat out fcirc 8 trials out of 10 when I switched back to default Single Type for the FC3 sub!!!

Not what I expected, but something I saw yesterday when playing around with mods of Dav's starting code.

8 out of 10 trials FC3 was faster with optimized compiler and using _Display to show completely drawn circles:
Code: (Select All)
_Title "FC3 versus fcirc QB64pe v3.13.1" ' b+ 2024-08-29
'Dav, AUG/2024 bplus mod 2024-08-28  try faster FC2 mod of fc

' 2024-08-29 try larger circles all on screen with FC3
$Checking:Off
Screen _NewImage(1000, 700, 32)
_ScreenMove 150, 0
Randomize Timer
Print "Overlapping lines check of FC2"
FC3 500, 350, 300, &H200000FF ' check for overlapping lines
Print "Looking good! no lighter lines." ' FC passes too BTW
Print: Print " zzz... press any for timed test"
Sleep
Cls
For i = 1 To 10 ' in case going first has disadvantage
    'time the fc sub
    t# = Timer
    For c = 1 To 2000
        fcirc Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        _Display
    Next
    t1# = t1# + Timer - t#

    'time the fc2 sub
    t# = Timer
    For c = 1 To 2000
        FC3 Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        _Display
    Next
    t2# = t2# + Timer - t#
Next
Print
Print "fcirc ="; t1#
Print "  FC3 ="; t2#
Print

If t2# < t1# Then
    Print "FC3 wins!"
ElseIf t1# < t2# Then ' EDIT fixed!
    Print "fcirc wins!"
Else
    Print "Tie fcirc = FC3 time"
End If
_Display
Sub fc (cx, cy, r, clr&)
    For y = -r To r
        x = Int(Sqr(r * r - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
    Next
End Sub

Sub FC3 (cx, cy, r, clr&)
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    y = 1
    r2 = r * r ' Dav mod
    While y <= r
        x = Int(Sqr(r2 - y * y)) ' r2 Dav
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        y = y + 1
    Wend
End Sub


Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

I am curious if your results differ? on both Windows and Linux systems
b = b + ...
Reply
#18
I thought Steve put it in a 'butshell' for us? Steve, what kind of a typo was that... miss hit the "N" key or the second 'T' didn't print? If the latter, why can't I find a buttcracker at Amazon? So far all Google gives me is the links to local plumbers.

Now not in regard to circle fill, but in regard to speed, I swear version 3.14 seems to take longer to compile source code. If so, for now the trade off for all the added bells and whistles is worth it. I sure hope, if I'm right, this won't be an issue in subsequent releases because I feel the need for speed!

Pete Big Grin
Shoot first and shoot people who ask questions, later.
Reply
#19
Hey @bplus.  I'm getting about 50/50 results with v3.13.0 under Linux.

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#20
Seriously guys, with results this close I will assert you can't tell which is faster by running the programs due to the various background processes always running in any operating system. So if consistent results are impossible, how can such small and inconsistent measurements be noteworthy?

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 11 Guest(s)