Restored from previous forum. Originally posted by Danilo.
I added a timing routine to your loop:
Code: Select all
xmax=640
ymax=400
maxcolor=15
leftside.f =-2
top.f =1.25
xside.f =2.5
yside.f =-2.5
xscale.f = xside / xmax
yscale.f = yside / ymax
temp1.f = xscale+leftside
If InitSprite()=0 Or InitKeyboard()=0
beep_(300,300):End:EndIf
OpenScreen(640,400,32,"")
begin = GetTickCount_()
For y=1 To ymax
For x=1 To xmax
cx.f=x*xscale+leftside
cy.f=y*yscale+top
zx.f=0
zy.f=0
colorcounter=0
While (Pow(zx,2)+Pow(zy,2)<4 And colorcounter<maxcolor)
tempx.f =Pow(zx,2)-Pow(zy,2)+cx
zy =2*Pow(zx,2)+cy
zx =tempx
colorcounter+1
Wend
StartDrawing(ScreenOutput())
Plot(x,y,colorcounter*$111111)
StopDrawing()
Next
FlipBuffers()
Next
final = GetTickCount_()-begin
Repeat
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
MessageRequester("TIME",StrU(final,2)+" ms",0)
and changed the code a bit after that:
Code: Select all
#xmax=640
#ymax=400
#maxcolor=15
leftside.f =-2
top.f =1.25
xside.f =2.5
yside.f =-2.5
xscale.f =xside/#xmax
yscale.f =yside/#ymax
Dim ColorBuffer(#xmax,#ymax)
Structure LONG
l.l
EndStructure
If InitSprite()=0 Or InitKeyboard()=0
beep_(300,300):End:EndIf
OpenScreen(#xmax,#ymax,32,"")
StartDrawing(ScreenOutput())
Buffer = DrawingBuffer()
Pitch = DrawingBufferPitch()
PixelFormat = DrawingBufferPixelFormat()
begin = GetTickCount_()
For y=0 To #ymax-1
*Line.LONG = Buffer+y*Pitch
For x=0 To #xmax-1
cx.f = x * xscale + leftside
cy.f = y * yscale + top
zx.f = 0
zy.f = 0
colorcounter = 0
PowZX.f = zx*zx;Pow(zx,2)
PowZY.f = zy*zy;Pow(zy,2)
While (PowZX+PowZY)<4 And colorcounter<#maxcolor
tempx.f = PowZX - PowZY + cx
zy = 2 * PowZX + cy
zx = tempx
colorcounter + 1
PowZX = zx*zx;Pow(zx,2)
PowZY = zy*zy;Pow(zy,2)
Wend
*Line\l = colorcounter*$111111
*Line+4
Next
FlipBuffers()
Next
StopDrawing()
FlipBuffers()
final = GetTickCount_()-begin
Repeat
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
MessageRequester("TIME",StrU(final,2)+" ms",0)
I didnt change anything in your algorithm
or in the general structure.
Times:
18.667 - your version
05.318 - my version
3.5 times faster, but i think there could be
a problem on some cards with the PixelFormat.
I think Fred can tell us more about this problem...
The speed would be much better if you calculate all
and display it at the end - so no FlipBuffers() is
needed in every loop.
Well, lets try it:
Code: Select all
#xmax=640
#ymax=400
#maxcolor=15
leftside.f =-2
top.f =1.25
xside.f =2.5
yside.f =-2.5
xscale.f =xside/#xmax
yscale.f =yside/#ymax
Dim ColorBuffer(#xmax,#ymax)
Structure LONG
l.l
EndStructure
If InitSprite()=0 Or InitKeyboard()=0
beep_(300,300):End:EndIf
OpenScreen(#xmax,#ymax,32,"")
begin = GetTickCount_()
For y=0 To #ymax-1
For x=0 To #xmax-1
cx.f = x * xscale + leftside
cy.f = y * yscale + top
zx.f = 0
zy.f = 0
colorcounter = 0
PowZX.f = zx*zx;Pow(zx,2)
PowZY.f = zy*zy;Pow(zy,2)
While (PowZX+PowZY)<4 And colorcounter<#maxcolor
tempx.f = PowZX - PowZY + cx
zy = 2 * PowZX + cy
zx = tempx
colorcounter + 1
PowZX = zx*zx;Pow(zx,2)
PowZY = zy*zy;Pow(zy,2)
Wend
ColorBuffer(x,y) = colorcounter*$111111
Next
Next
StartDrawing(ScreenOutput())
Buffer = DrawingBuffer()
Pitch = DrawingBufferPitch()
PixelFormat = DrawingBufferPixelFormat()
For y=0 To #ymax-1
*Line.LONG = Buffer+y*Pitch
For x=0 To #xmax-1
*Line\l = ColorBuffer(x,y)
*Line+4
Next
Next
StopDrawing()
FlipBuffers()
final = GetTickCount_()-begin
Repeat
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
MessageRequester("TIME",StrU(final,2)+" ms",0)
Much better, IMHO.
Result:
18.667 - your version
05.318 - my 1st version ( 3.5 times faster )
00.120 - my 2nd version ( 155 times faster )
Maybe it helps a bit... but like i said,
there could be a problem with PixelFormat
on some graphics cards.
My rules for measurement:
- Start is before the loop
- End is after the image is generated _and_ displayed
You told me on IRC you like to see the image
while its generated, but with the fast version
this is not needed anymore - IMO.
120ms should be OK... and of course its much better on
faster CPUs (tested with my old PIII-600 internet PC only).
cya,
...Danilo
(registered PureBasic user)