Page 2 of 3
Posted: Fri Jul 02, 2004 1:40 pm
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?
Posted: Fri Jul 02, 2004 3:10 pm
by thefool
@dige: thanks

Posted: Fri Jul 02, 2004 5:31 pm
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
Posted: Sat Jul 03, 2004 1:57 am
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
Posted: Sat Jul 03, 2004 9:36 am
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:

Posted: Sat Jul 03, 2004 9:47 am
by Dreglor
hmm what version of pb are you using?
this is what i am getting

Posted: Sat Jul 03, 2004 10:35 am
by Froggerprogger
I use PB 3.90 on Win2000 (1GHz Athlon / Asus A7A266 / Geforce 2 MX)
Posted: Sat Jul 03, 2004 11:12 am
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

Posted: Sat Jul 03, 2004 12:38 pm
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?
Posted: Sat Jul 03, 2004 12:56 pm
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
Posted: Mon Jul 05, 2004 2:08 pm
by remi_meier
PB: (Dynamic CPU) 1200
GLB.: 1000
VC: 600
Blitz: 500
VB: 500
DarkB: 10pix/s
PB is GREAT!!!
[EDIT]If the whole screen is black, GLB. is 100kpix/s faster

[/EDIT]
Posted: Mon Jul 05, 2004 3:43 pm
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.
Posted: Mon Jul 05, 2004 6:00 pm
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
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
Posted: Mon Jul 05, 2004 6:41 pm
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.
Posted: Mon Jul 05, 2004 7:21 pm
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