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:

Post by GedB »

Interesting. On my PC Purebasic is still performing poorly.

I wonder why? Perhaps it has something to do with the fpu?

Anybdoy else getting similar results to me?
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

@dige: thanks :)
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

When doing speed test, you need to respect the original benchmarks. All are in windowed mode, so doing it too. Just changing this gains about 100 kpx/sec. Also, the VC.net and VB example aren't double buffered, which is not the same at all (but I can't change them). Writing on a visible video surface is more restrictive than writing on a backbuffer. On the final test, PB is around 700 kpix/secs when GLbasic is 600 kpix/sec. There is some strange line on the PB example, may be a computation is wrong too.

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()

  OpenWindow(0, 0, 0, #x1, #y1, #PB_Window_SystemMenu, "Test")
  If OpenWindowedScreen(WindowID(), 0, 0, #x1, #y1, 0, 0, 0)
    
    Repeat 
      While WindowEvent() : Wend
      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

EndIf 
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

i not sure if that code is from the first example but it really is screwy
i post a screen later if needed
so either the code it not 100% bug free (*ahem* we all make mistakes, right?)

or pb it self has a problem
~Dreglor
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Where is the problem ? With old declared as float all looks fine here and it is fast as GLBasic, and they both are much faster than all others.
This should be the correct result:
Image
%1>>1+1*1/1-1!1|1&1<<$1=1
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

hmm what version of pb are you using?

this is what i am getting
Image
~Dreglor
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

I use PB 3.90 on Win2000 (1GHz Athlon / Asus A7A266 / Geforce 2 MX)
%1>>1+1*1/1-1!1|1&1<<$1=1
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

oh well that explains somthings
i have the 3.91 beta 2
i guess what ever fred changed in the beta it was not right :)
~Dreglor
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

I use 3.91 beta 2 also, and it works perfect. And I guess Fred uses 3.91 beta 2, too. Maybe something wrong with your gfx card/drivers?
El_Choni
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Dreglor,

Here is the same code using WindowOuput() instead of DirectX. Does it display OK on your PC?

Does the GL Version display OK?

Code: Select all

; --------------------------------- ;
; Project: Mandelbrot - Speedtest without DirectX
; 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 OpenWindow(0, 0, 0, #x1, #y1, #PB_Window_SystemMenu, "Test")
  While WindowEvent() : Wend
  xende = xende * fac
  xstart = xstart * fac
  ystart = ystart * fac
  yende = yende * fac
  xzoom = (xende - xstart) / #x1
  yzoom = (yende - ystart) / #y1
  timer = GetTickCount_()
  StartDrawing(WindowOutput())
  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.")
  StopDrawing()
  FlipBuffers()
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
EndIf
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

:D

PB: (Dynamic CPU) 1200
GLB.: 1000
VC: 600
Blitz: 500
VB: 500
DarkB: 10pix/s :lol:

PB is GREAT!!!


[EDIT]If the whole screen is black, GLB. is 100kpix/s faster :? [/EDIT]
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

I've changed the threads title, seems PB does do well after all.

I would like to know why my machine is slower for PB. There must be something going on there.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

Just to say:
This GLBasic man used SUB's and I read on his page, that the functions and SUBs are the same in GLBasic.... I replaced the mandelbrot() whith a GoSub and we have 100Kpix/s more :lol:

About your Problem GedB:
I know that GLBasic uses OpenGL and PB uses DirectX, so look at your preferences for your GFX-Card. Perhaps you have to change something to have a fair result!

bye
remi
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

As I said, I don't think it is the drawing functions.

If I remove the drawing functions completely, the rate doesn't increate that much.

All of the work is being done in the DotsColor procedure.

I reckon that they are relying on some customer floating point code, whereas PB is relying on the maths co-processor.

I don't know how I would go about testing this idea.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

What I just can answer is that the Mandelbrot calculation used in the GLBasic benchmark is not the one I use to do, and performances are not the same at all ...

If you are interested to test ... change DotsColor() with this one :

Code: Select all

Procedure.f MB(xf.f, yf.f)
  fx.f = xf
  fy.f = yf
  j.l = 0
  u.f = 0.0
  v.f = 0.0
  While j <= #max And (u + v) < 4.0
    u = fx * fx
    v = fy * fy
    fy = 2.0 * fx * fy + yf
    fx = u - v + xf
    j + 1
  Wend
  ProcedureReturn j / #max
EndProcedure
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.
Post Reply