BMAX vs B3D

BlitzMax Forums/BlitzMax Programming/BMAX vs B3D

Hi, just playing around with the demo version of BMAX.

Been searching the site for speed differences with B3D and it seems BMAX is faster for maths etc. but what I'm finding is that commands such as PeekByte are 5 to 6 times slower!

Is this due to the way BMAX works compared with B3D?
i.e. are all 'highlighted' commands slower?

Any advice appreciated
Marg

Have some example code (and preferably a binary too since I no longer have a working version of Blitz3D)?

Using a bank's byte pointer directly will be faster in BlitzMax (see the BankBuf function).

Writing then reading, 100 million Integers to/from Banks

2057ms in Blitz3D
841ms in Max
;B3D...
b=CreateBank(100000000*4)
time=MilliSecs()
For i=0 To 99999999
  PokeInt b,i*4,i
Next
For i=0 To 99999999
  x=PeekInt(b,i*4)
Next
time=MilliSecs() - time
Print time
WaitKey


'Max...
Local b:TBank=CreateBank(100000000*4)
Local buf:Int Ptr=Int Ptr(BankBuf(b)) 'recasting OWNS! :)

Local time=MilliSecs()
Local i:Int,x:Int

For i=0 To 99999999
  buf[i]=i
Next
For i=0 To 99999999
  x=buf[i]
Next
time=MilliSecs() - time
Print time


I've been using this way here as well ... probably not a great idea to rely heavily on Poke and Peek in max. .. especially as you have to pass the number/handle of the memory bank every time (for memory protection purposes). It is much faster to cast it with pointer[0] or whatever, as above.

Also with the `Long` type, you can move 8 bytes at a time.

Thanks, does this mean that byte access is not possible using this method?

(looks like it is treated like an array)

Marg

You just use a byte ptr instead of int ptr to read by the byte. It's all well and good saying it's faster in max with pointers, but the higher level stuff should work reasonably well, too. Can you post your original max code, Marg?

tip:

do not write

bank:int=createbank(...)

write

bank:Tbank=createbank(...)

this is much faster - and a bit faster than in bb-classic...

Thanks,

Nomen luni, the code is just like Toms earlier in the thread. The B3D bit run in BMax.

Does this mean we have to access Byte,Short,Int, etc like in an array? But if using peek/poke we can load/store any byte,short,int anywhere?

Marg

Hi,

Did some speed tests.

1) B3D with Toms Code takes 177
2) BMax with Toms 'BankBuf' Code takes 52
3) BMax with Toms poke/peek code takes 902

However as MrCredo says about :TBank reduces 3) down to 232 which is much nearer B3D time. Thanks MrCredo.

Here is the peek/poke using :TBank for BMax

Local b:TBank=CreateBank(10000000*4)
Local time:Int=MilliSecs()
Local i,x:Int

For i=0 To 9999999
PokeInt b,i*4,i
Next
For i=0 To 9999999
x=PeekInt(b,i*4)
Next

time=MilliSecs() - time
Print time

Thanks everyone
Marg

Well done all - you got to the bottom of it. In answer to your question 'Do we have to read it like an array (if using pointers)' - the answer is you can read it how you like.

Say you wanted to read an int, then a byte. Get an int pointer as per Tom's max code. Read an int from the start using buf[0]. Add one to buf. As max knows buf is a pointer to int, it moves forward in memory the size of an int (4 bytes I think), to the address directly after the int. Now cast buf to a byte pointer. Buf[0] returns the value of the byte. Add one to buf skips to the memory directly after the byte. The beauty of pointers is that they know the size of what they point to, so you dont have to worry what the size of an int, byte,float etc is. This type of recasting can become a pain and banks are ideal for reading data of varied types.

@Marg:

Use

Local b:TBank=CreateBank(10000000*4)
Local time:Int=MilliSecs()
Local i,x:Int

For i=0 To 9999999
b.PokeInt i*4,i
Next
For i=0 To 9999999
x=b.PeekInt(i*4)
Next

time=MilliSecs() - time
Print time


Pure OO for Speed...
Because with PokeInt(Bank,...) Bmax must look intern to int handles.
If you need speed, use only the Object Oriented version, not pieces like MrCredo said....
Mfg Suco

Hi, just a note to say that the code from Suco-X runs at 155 ms which is actually faster than B3D using poke/peek in both.

Thanks all
Marg