Page 1 of 2

BlitzBasic NOT 4X faster drawing!!

Posted: Mon Jun 02, 2003 6:09 am
by Revolver
I'm debating whether or not to do my 2D game in BlitzBasic or PureBasic. Blitz attracts me because of its ease of use and speed, Pure attracts me because of its small exe size, built-in alpha effects, and more advanced language constructs like pointers, structures, and linked lists(all bb has are arrays and types). I knew the Blitz was blazing fast with the 2D drawing commands, so I set up a simple test to see how PureBasic would compare. The following is the code I used for each version:

PureBasic

Code: Select all

InitSprite()
InitKeyboard()
OpenScreen(640, 480, 16, "Sprite Test")
LoadSprite(0, "Data\nebula3.bmp", #PB_Sprite_Memory)

ChangeGamma(0,0,0,1)

timesum   = 0
framesum  = 0
timecheck = GetTickCount_()

Repeat
  
  framesum  = framesum + 1
  oldtime   = timecheck
  timecheck = GetTickCount_()
  deltatime = timecheck - oldtime
  timesum   = timesum + deltatime
  If timesum >= 1000
    frames  = framesum / (timesum / 1000)
    framesum = 0
    timesum = timesum - 1000
  EndIf
  
  FlipBuffers()
  
  DisplaySprite(0, 0, 0)
  
  StartDrawing(ScreenOutput())
    DrawingMode(1)
    Locate(10,10) : DrawText("FPS: "+ Str(frames))
  StopDrawing()
  
  ExamineKeyboard()

Until KeyboardPushed(#PB_Key_Escape)

End
BlitzBasic

Code: Select all

Graphics(640,480,16,1)
SetBuffer(BackBuffer())
Nebula = LoadImage("nebula3.bmp")

timesum   = 0
framesum  = 0
timecheck = MilliSecs()

Repeat
  
  framesum  = framesum + 1
  oldtime   = timecheck
  timecheck = MilliSecs()
  deltatime = timecheck - oldtime
  timesum   = timesum + deltatime
  If timesum >= 1000
    frames  = framesum / (timesum / 1000)
    framesum = 0
    timesum = timesum - 1000
  EndIf
  
  Flip(False)
  
  DrawBlock(Nebula,0,0)
  
  Text(10,10,"FPS: "+ frames)

Until KeyHit(1)

End
In both tests, the same file "nebula3.bmp" was used, and it is 640x480 pixels, at 24-bit color depth. It fills the screen completely. I turned off V-Sync in my video card's settings, so that the framerate wouldnt get hindered by my monitor's maximum refresh rate. Anyway, here are the results:

PureBasic[640x480@32bit] - 275 FPS
PureBasic[640x480@16bit] - 520 FPS

Not bad! This is far higher FPS than anyone would ever need, but.. this is just drawing 1 image to the screen. Now lets look at BlitzBasic's results:

BlitzBasic[640x480@32bit] - 1111 FPS
BlitzBasic[640x480@16bit] - 2155 FPS

BlitBasic is almost exactly 4 times faster at this operation than PureBasic is(a little faster actually)! Why is this? It would seem that PureBasic would be faster, because they both use DirectX 7, but Blitz automatically updates the mouse and keyboard every frame, but PureBasic only does it when I tell it to(in this case, the mouse isn't updated at all). Also, BlitzBasic's text() command is notoriously very slow, could PureBasic's be even worse? I'm interested to find out what's going on here, as I was going to choose PureBasic for my game due to its robust features, but.. I also want my game to be able to be run well on very low-end machines, and BlitzBasic's blazing speed would do that very well.

I ran this test on my AMD Athlon 2400+, 512MB PC2100 DDR, ATI Radeon 8500 LE 128MB pc.

Posted: Mon Jun 02, 2003 6:15 am
by Revolver
By the way I used BlitzBasic 2D version 1.68, which is quite old. It relies on DirectX 7 like PureBasic. The new BlitzPlus uses only DirectX 1 (!), and supposedly has increased drawing speed because of this backwards step. I don't know how this Mark Sibly character does it, but he must be doing something right!

Posted: Mon Jun 02, 2003 9:14 am
by Fred
It could be 2 problems:

1) Yes, text drawing are very slow (antiased etc.., not suitable at all for games).

2) The VSync is always activated on PB. Be sure, it is activated on the blitz side too

These kind of benchmarks are really nonsense, as you won't use the Text() commands at all in a game. So I suggest better to remove it from the benchmark and compare the final score at the end of the loop. PB is usually a bit faster on sprite commands than BB. About the DX1 stuff, it always made me laugh about the potential speed increase, as if DX7 is installed, all previous version wrap to the new one, which makes it actually a bit slower. The only advantage (and I think it worth it) is the Windows NT 4 compatibility.

Posted: Mon Jun 02, 2003 9:16 am
by Fred
Just re-read the post again:

What is that ?!

> LoadSprite(0, "Data\nebula3.bmp", #PB_Sprite_Memory)

It loads the sprite in main system memory and disable all hardware acceleration...

Posted: Mon Jun 02, 2003 4:48 pm
by Codemonger
I don't think these tests are accurate at all, as the directx pipeline is the same in any language as far as passing vertices or blitting sprites to the screen. If you really want to do a speed comparison try running a for next loop , 1000000000 (100 million times) with calculations in between. This is the true test of a programming language. You will notice that BlitzBasic will take a long time to compute this. PureBasic should take under 2 seconds. So when you create a large game and need computing power I would suggest you stick with PureBasic as it is fast enough to handle any scene with many calculations per frame. Blitz Basic is just showy, but severly lacks in the large scene/entity management department, don't waste your time. Also I agree with Fred about the text() command in the loop. Text is not supported by hardware at all. If you want to use text create a bitmap font and blit that to the screen using pre-made functions. That will increase speed 10 times over, because it is done in hardware.

Posted: Mon Jun 02, 2003 4:56 pm
by PB
> LoadSprite(0, "Data\nebula3.bmp", #PB_Sprite_Memory)
> It loads the sprite in main system memory and disable all hardware
> acceleration...

Exactly. Change #PB_Sprite_Memory to 0 and you'll get a better speed.

Posted: Mon Jun 02, 2003 4:57 pm
by Codemonger
The above test I did on my test machine (400mhz 32MB video 256ram etc..) and Purebasic definately kills the competition. In the pseudo graphic programming languages Mark Sibley does have one of the faster ones out there(compared to darkbasic, rad3d & all that other junk), but it will never be able to compete with PureBasic on the professional level of speed, which is what a game really relies on.

Posted: Mon Jun 02, 2003 6:07 pm
by GedB
Revolver,

Did you turn off debugging?

I have a mandelbrot set that takes 7830 ms with debugging but a lightning fast 2907 without.

Posted: Mon Jun 02, 2003 6:11 pm
by Henrik
Hi Revolver
i haven't read all the above answers to your post, But anyway
In the blitz code your are using Flip(False) = vsynk is off
If you wanna compare, you need to use Only "Flip" in the blitz code.
so try it out without thje (false).

Blitz with Flip(false) = about 1900
Blitz with only Flip = about 60
Geforce (1) cele 450Mz

Bedst regards
Henrik

Posted: Mon Jun 02, 2003 6:32 pm
by Revolver
About V-Sync, I completely disabled it in my video card's hardware setup dialog, so even if PB uses it by default, since the setting is disabled in hardware it will be ignored and run as fast as possible. If it was on, I would max out at 85 FPS in PB, which as you can see, is not the case. Yes, debugging was off.

And haha! I am stupid, I knew something was wrong! When not loading into system memory, PB gets the following scores:

640x480@16: 2000 FPS
640x480@32: 1070 FPS

Still lower, but this is probably due to the text commands. While Blitz does have very nice UDP support(*cough* fred might want to take a look at it *cough*), I think I'll be using PB for my game :)

Sorry for my dumb mistake and possibly upsetting some people greatly ;)

Posted: Mon Jun 02, 2003 6:47 pm
by Paul
Also note that PB uses antialias on the text to blend it beautifully with the background image... BB does not, resulting in blocky edge text.

Mark gave up on antialias long ago because he could not implement it without problems (at least that's the reply he gave me). It was only available in the first few releases of BB before being dropped.

Posted: Mon Jun 02, 2003 7:06 pm
by Revolver
I took Codemonger's advise and tried a test that would probably be a bit more accurate:

PureBasic

Code: Select all

InitSprite()
OpenScreen(640, 480, 32, "Sprite Test")
LoadSprite(0, "Data\nebula3.bmp", 0)

ChangeGamma(0,0,0,1)

starttime = GetTickCount_()

For I = 1 To 100000
  FlipBuffers()
  DisplaySprite(0, 0, 0)
Next

stoptime = GetTickCount_()

elapsedtime = stoptime - starttime
MessageRequester("Elapsed Time",Str(elapsedtime) +" milliseconds",0)

End
BlitzBasic

Code: Select all

Graphics(640,480,32,1)
SetBuffer(BackBuffer())
Nebula = LoadImage("nebula3.bmp")

starttime = MilliSecs()

For I = 1 To 100000
  Flip(False)
  DrawBlock(Nebula,0,0)
Next

stoptime = MilliSecs()
elapsedtime = stoptime - starttime

SetBuffer(FrontBuffer())
Print(Str(elapsedtime) +" milliseconds")
WaitKey()

End
Results:
PB@16 - 44609 Milliseconds
BB@16 - 44583 Milliseconds
PB@32 - 87922 Milliseconds
BB@32 - 87995 Milliseconds

They're almost exactly the same, BB beats out PB at 16 bit by 26 milliseconds, but PB beats BB at 32 bit by 73 milliseconds. If I ran it again, the results could be different, but oh well. They're as good as the same speed.

Posted: Mon Jun 02, 2003 7:12 pm
by Fred
That's what I expected, you can't Tweak DirectX. And now, see the validity of the information when some guys say than DX1 is faster than DX7...

Posted: Mon Jun 02, 2003 7:20 pm
by Revolver
I would but I'm not willing to shell out another $60 for BlitzPlus when all it adds is that questionable DX1 'speed', and some gadget commands that will take years to catch up to PB's excellent command set

Posted: Mon Jun 02, 2003 8:59 pm
by Codemonger
Hi Revolver,
the test I was suggesting was just a pure number crunching test that will indicate how many and how fast can you do simple calculations.

So lets take your example test code and change it a bit to: (also test this in VB, Blitz Basic, and all others. Remember to take debug off)

Code: Select all

starttime = GetTickCount_() 

y = 5 
For I = 1 To 100000000
 x = x + y * 1.000001
Next 

stoptime = GetTickCount_() 

elapsedtime = stoptime - starttime 
MessageRequester("Elapsed Time",Str(elapsedtime) +" milliseconds",0) 
now doing tests on who blits to the screen faster or what draws faster is not a real test. Because how you get real speed in game programming is not what you draw but what you don't draw. And that is figured out with calculations. The reality is you will only send a handfull of images to the render pipeline in directx X, your job as a programmer is to figure out what gets sent. So speed of rendering is not an issue as that is mainly dealt with in hardware, unless you plan to render 10000 bouncing balls. But even then you get into issues of bandwidth of the rendering pipeline which is 25MB/s or something. So as a good game programmer you will want to be able to do as many calculations within each frame as possible. So when you want to compare speeds of compilers, next time do calculations in a loop or something. This is a more powerful test, and again purebasic is much faster in the areas of most importance.