Mandelbrot speed test - PB shifts some

Everything else that doesn't fall into one of the other PB categories.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Mandelbrot speed test - PB shifts some

Post by GedB »

GLBasic offers an interesting Mandelbrot speedtest comparison here:

http://www.glbasic.com/en/download.html

I've converted the code to Purebasic, but there are a few problems.

1) Something is going wrong with the floating point arithmatic, resulting in some incorrect colours.

2) It isn't running anywhere near as fast as the Blitz or GLEntries 8O.

Am I doing anything wrong. Can anybody fix it?

Improving the algorythm doesn't count.

Code: Select all

; --------------------------------- ;
; Project: Mandelbrot - Speedtest
; Start: Tuesday, September 09, 2003
; PB Version: 3.90
; Based on GLBasic code at http://www.glbasic.com/en/download.html
; Converted by Ged Byrne

#max.f = 128   ; #max iterations

#x1 = 640    ; ScreenX
#y1 = 480    ; ScreenY

xstart.f = -2.025
ystart.f = -1.125
xende.f = 0.6
yende.f = 1.125

xzoom.f = (xende - xstart) / #x1
yzoom.f = (yende - ystart) / #y1

fac.f = 0.99

Procedure HSB2RGB(hue.f, saturation.f, brightness.f)
  If brightness = 0 
    ProcedureReturn 0
  EndIf
  If saturation = 0 
    ProcedureReturn RGB(brightness*255, brightness*255, brightness*255)
  EndIf
  DefType.f red, green, blue, domainOffset
  If hue < 1.0/6
    ; red domain; green ascends
    domainOffset = hue
    red   = brightness
    blue  = brightness * (1.0 - saturation)
    green = blue + (brightness - blue) * domainOffset * 6
  ElseIf hue < 2.0/6
    ; yellow domain; red descends
    domainOffset = hue - 1.0/6
    green = brightness
    blue  = brightness * (1.0 - saturation)
    red   = green - (brightness - blue) * domainOffset * 6
  ElseIf hue < 3.0/6
    ; green domain; blue ascends
    domainOffset = hue - 2.0/6
    green = brightness
    red   = brightness * (1.0 - saturation)
    blue  = red + (brightness - red) * domainOffset * 6
  ElseIf hue < 4.0/6
    ; cyan domain; green descends
    domainOffset = hue - 3.0/6
    blue  = brightness
    red   = brightness * (1.0 - saturation)
    green = blue - (brightness - red) * domainOffset * 6
  ElseIf hue < 5.0/6
    ; blue domain; red ascends
    domainOffset = hue - 4.0/6
    blue  = brightness
    green = brightness * (1.0 - saturation)
    red   = green + (brightness - green) * domainOffset * 6
  Else
    ; magenta domain; blue descends
    domainOffset = hue - 5.0/6
    red   = brightness
    green = brightness * (1.0 - saturation)
    blue  = red - (brightness - green) * domainOffset * 6
  EndIf
  ProcedureReturn RGB(red * 255, green * 255, blue * 255)
EndProcedure

Procedure.f DotsColor(xval.f, yval.f) ; color value from 0.0 to 1.0 by iterations
  DefType.f i, m, r, j
  While (j < #max) And (m < 4.0)
    j=j+1
  	m = r * r - i * i
    i = 2.0 * r * i + yval
    r = m + xval
  Wend
  ProcedureReturn j / #max
EndProcedure

Procedure mandelbrot(xstart.f, ystart.f, xzoom.f, yzoom.f) ; calculate all points
  DefType.f h, old
  For x = 0 To #x1 - 1
    For y = 0 To #y1 - 1
      h = DotsColor(xstart + (xzoom * x), ystart + (yzoom * y)) ; color value
      If h <> old
        b = 1.0 - h * h ; brightness
        col = HSB2RGB(h, 0.8, b)
        old = h;
      EndIf
      Plot(x, y, col)
    Next
  Next
EndProcedure

If InitKeyboard() And InitSprite() And OpenScreen(#x1, #y1, 16, "Mandelbrot")
  Repeat
    xende = xende * fac
    xstart = xstart * fac
    ystart = ystart * fac
    yende = yende * fac
    xzoom = (xende - xstart) / #x1
    yzoom = (yende - ystart) / #y1
    timer = gettickcount_()
    StartDrawing(ScreenOutput())
    mandelbrot(xstart.f, ystart.f, xzoom.f, yzoom.f)
    timer = gettickcount_() - timer
    speed = Int(#x1*#y1 / (1+(timer)))
    Locate(0,0)
    DrawText("Speed: " + Str(speed) + " Kpix/sec.  Press and hold escape to exit")
    StopDrawing()
    FlipBuffers()
  Until ExamineKeyboard() And KeyboardPushed(#PB_Key_Escape)
EndIf
Edit - Fixed Deftype for old in DotsColor
Last edited by GedB on Tue Jul 06, 2004 1:55 pm, edited 3 times in total.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

My results:

BB 3D ~229 Kpx/sec
DarkBasic ~60 px/sec (slow as hell, I see each column seperate built within some seconds)
DarkBasicPro missing runtime DLL
GLBasic ~670 Kpx/sec
VB6 ~240 Kpx/sec
VC.net ~280 Kpx/sec

and PB ~580 Kpx/sec


-> So PB is about 2 times faster than all others except of GLBasic.
But yes, there are strange stripes inside the fractal.
hmmmm.
%1>>1+1*1/1-1!1|1&1<<$1=1
Saboteur
Enthusiast
Enthusiast
Posts: 273
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

Debugger.... Have you switch off the debugger????
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Interesting. I have compiled to exe, so no debugger, and my results differ:

PB ~ 275 Kpx/sec

BB 3D ~480 Kpx/sec
GLBasic ~560 Kpx/sec
VB6 ~330 Kpx/sec
VC.net ~390 Kpx/sec

I think this may be because PB is working full screen and I don't have a graphics card. Will check.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

I guess it's a mistake in the code that makes those bad lines in the 'dark' area ...

In mandelbrot procedure, you should declare old as the same type than h otherwise the test runs bad.

By the way results I have a close to Froggerprogger's. Possible to win 10-15% in performances changing some lines. ie you may change the line h = DotsColor() storing arguments differently before to save some calculation.

Also the plot may be changed by a PokeL or a few ASM using DrawingBuffer().

I did not look in detail other Basic's sources to understand what is comparable.

Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Oh, and you have to admit, this GL Basic is rather impressive.
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

I bet it would be faster using the DrawingBuffer() commands instead of Plot(). Maybe somebody who fully understands them (unlike me) would be able to help you out. PB might not be so slow then.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Look at your Procedure mandelbrot...
You are comparing h.f to old.l
You must compare the same types so also define old as a float

DefType.f h,old
Image Image
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Paul,

Thanks. That clears up the stripes.

I suspect that the calculation for the time is wrong somehow.

The VB version is scoring higher, but you can see that it is slower.

Code: Select all

speed = Int(#x1*#y1 / (1+timer))
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

what is best buy?
GLbasic or Blitz3d?

i cant find enough documentation to 3d in PB.
Besides, i dont like it only taking mesh files.

But if you have a site with proper doc's for a 3d programming newbie, please tell me, and let me save a lot of money!
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

I don't think drawing buffer will make much difference, since commenting out code so that nothing gets plotted makes very little difference to the results.

All of the time is taken up in the DotsColor() function.

Replace dots color so that it simple returns a random number and see how fast it flies.

It looks to be PB's floating point arithmatic that is letting it down.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

For me it's almost as fast as the GLbasic example when doing the change that Paul pointed out in his post.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

doing no change only switching off the debugger:
980 kpx/sec.

same as the best of the other examples.
dige
Addict
Addict
Posts: 1416
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

thefool wrote: i cant find enough documentation to 3d in PB.
Besides, i dont like it only taking mesh files.

But if you have a site with proper doc's for a 3d programming newbie, please tell me, and let me save a lot of money!
@TheFool: please take a look at this: viewtopic.php?p=62046#62046

regards dige
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Here PB is now as fast as GLBasic (with old.f), too
All the other implementations are much slower, see above.
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply