Is Max slower than Blitzplus for pixel plotting?

BlitzMax Forums/BlitzMax Beginners Area/Is Max slower than Blitzplus for pixel plotting?

Matty(Posted 2006) [#1]
Hello,

I just downloaded the demo of blitzmax to compare the speed of drawing individual pixels with blitzmax as opposed to blitzplus.

Looking through the documentation, and reading some of the posts here I could find only one way of writing pixel information directly to the backbuffer().

This was - grab pixmap of screen, writepixel to the pixmap, drawpixmap to the screen, release grabbed pixmap.

Comparing this, for the same area of the screen (100 pixels by 100 pixels), to a test done in blitzplus on the same computer, gave a result which showed the blitzplus is a lot faster for individual pixel plotting.

I'd like to know if the method I'm using is flawed to compare the speed of the two languages with respect to pixel plotting.

The speed difference, on an old machine, was 53 frames per second (about 20 millisecs per frame) in blitzmax compared to 145 frames per second (about 7 millisecs per frame) in blitzplus.


Here is the code in blitzplus:
Graphics 800,600,32

Repeat
Cls

LockBuffer

For pixel=1 To 10000
WritePixelFast pixel/100,pixel Mod 100,pixel


Next
UnlockBuffer

fpscount=fpscount+1
If MilliSecs()-fpstime>1000 Then

fpstime=MilliSecs()
fps=fpscount
fpscount=0

EndIf 

Text 500,0,"FPS:"+fps
Flip False 


Until KeyDown(1)
End


and here is the code in blitzmax:

Graphics 800,600,32

Repeat

fpscounter=fpscounter+1
If MilliSecs()-fpstime>1000 Then
fpstime=MilliSecs()
fps=fpscounter
fpscounter=0

EndIf 
Cls

pixmap=GrabPixmap(0,0,101,101)

For pixel=1 To 10000
WritePixel pixmap,pixel / 100,pixel Mod 100,pixel
Next

DrawPixmap pixmap,0,0
Release pixmap

DrawText "FPS:"+fps,500,0

Flip False

Until KeyHit(key_escape)
End


Having not used blitzmax before I am sure there must be a better way of doing what I did in blitzplus which is of comparable speed.

Thanks,


fredborg(Posted 2006) [#2]
There is no point in grabbing the buffer every frame, you can do it like this instead:
Graphics 800,600,0,0


Local pixmap:TPixmap = CreatePixmap(101,101,PF_RGBA8888)

Repeat

	fpscounter=fpscounter+1
	If MilliSecs()-fpstime>1000 Then
		fpstime=MilliSecs()
		fps=fpscounter
		fpscounter=0
	EndIf 
	Cls

	For pixel=1 To 10000
		WritePixel pixmap,pixel / 100,pixel Mod 100,pixel
	Next

	DrawPixmap pixmap,0,0

	DrawText "FPS:"+fps,500,0

	Flip False

Until KeyHit(key_escape)
End
Or just plot the pixels instead:
Graphics 800,600,0,0

Repeat

	fpscounter=fpscounter+1
	If MilliSecs()-fpstime>1000 Then
		fpstime=MilliSecs()
		fps=fpscounter
		fpscounter=0
	EndIf 
	Cls

	For pixel=1 To 10000
		SetColor 0,0,pixel/100
		Plot pixel / 100,pixel Mod 100
	Next

	DrawText "FPS:"+fps,500,0

	Flip False

Until KeyHit(key_escape)
End



Matty(Posted 2006) [#3]
Hi Fredborg - the second one you showed is really slow, but I guess that is because it is using 'plot' while the first one you listed doesn't display any graphics - I get the frame rate displayed but I cannot see anything whereas I could with the method I used before.


fredborg(Posted 2006) [#4]
The first one doesn't display any graphics? That's strange, it works fine here...

If you are on a PC (I guess so since you're using B+) you can try changing graphics driver, by placing this before the Graphics command:
SetGraphicsDriver GLMax2DDriver()
It might be faster, but it depends on your graphics card. It's a lot faster on my laptop.


Matty(Posted 2006) [#5]
Thanks Fredborg - that command 'setgraphicsdriver GLMax2dDriver' caused it to display the graphic (blue lines as expected). It also runs at a reasonable pace on my old system - about 120 frames per second (8-9 millsecs per frame), I'll have to try it on my other machine as well.


fredborg(Posted 2006) [#6]
Ok, sounds strange, but it might be a problem with either your graphics driver or the demo version of BlitzMax.

I get around 400FPS when using plot, and around 1200FPS when using a pixmap without grabbing the frame buffer. In B3D I get around 800FPS using your B+ example.


Matty(Posted 2006) [#7]
I didn't expect a high framerate on the machine I tested it on - 500 Mhz PC with Geforce 2. In b3d using my b+ example I get a much lower frame rate than both b+ and blitzmax, which is consistent with your results.

One point that concerns me though - in blitzplus/b3d I can write directly to the backbuffer, however in blitzmax I have to write to a pixmap - when I draw the pixmap to the screen do areas of the pixmap that I have not drawn to remain transparent or do I need to set the alpha of these pixels in the pixmap manually?


FlameDuck(Posted 2006) [#8]
I'd like to know if the method I'm using is flawed to compare the speed of the two languages with respect to pixel plotting.
Yes. http://www.m2p.dk/bb-bmx-firedemo.zip

It doesn't have a BlitzPlus version, but converting either the BlitzMAX/Blitz2D one is probably trivial.


Matty(Posted 2006) [#9]
Hi FlameDuck - Something must be wrong with my old PC's graphics drivers - I can see the image that comes in from the left but the blue/orange flames that grow do not display at all on my old machine (although they work perfectly on my other machine).

Would you be able to elaborate a little on your 'Yes' answer above please?

Thanks,