speed: bmax vs c++

BlitzMax Forums/BlitzMax Beginners Area/speed: bmax vs c++

CS_TBL(Posted 2007) [#1]
(edit: atn: BRL, hm.. not exactly beginner-level, feel free to move to the normal bmax section)

Still working on my texture-generator :P

But I was wondering. I just do array-reading/writing, and some math, all quite language-independent and low-level. Is there much difference regarding speed for this kinda stuff between BMax and C++? It's not that I'm that much of a C++ wizz, but filling an array shouldn't be too bad I figure and since one can include that kinda stuff with extern etc. . *if* I win something with it.


ImaginaryHuman(Posted 2007) [#2]
Use pointers instead of arrays. Arrays have an additional indirect jump for every access, it seems.


CS_TBL(Posted 2007) [#3]
hm.. and then? Is it then as fast as c++?


grable(Posted 2007) [#4]
Its hard to say, even one C++ can slower/faster than another C++.
It all depends on the assembler output in the end, and any added runtime "bonuses", ie BlitzMaxes GC.

So, in a small context i would say they are pretty equal.
But as a whole id have to say BlitzMax may be slower because of its GC.

Note, that i have not tested this at all. its just my uninformed opinion ;)


CS_TBL(Posted 2007) [#5]
uhm, the array/pointer thing:

consider this:
Type MyPixel
  Field r:int
  Field g:int
  Field b:int
End Type


Next on, my 'image' is simply an array of such MyPixel instances, like i[width*height], so normally I access my red pixels with i[x+width*y].r .
How to apply that array/pointer thing on that structure?


grable(Posted 2007) [#6]
You cant, since all types are allocated on the Heap your array would just be a collection of pointers.

Youd have to do it manually, for example:
Local p:Byte Ptr = SomeBuffer
' depending on your byte order/pixelsize
p[x+y*width*4] = red
p[(x+y*width*4)+1] = green 
p([x+y*width*4)+2] = blue



CS_TBL(Posted 2007) [#7]
That's quite bad. The MyPixel type also contains methods and other fields (as I also have indexed images 'n stuff), and I can't predict whether it'll even stay like this, so those potential offsets could vary. Well, I'll stick with arrays then.. :S


Azathoth(Posted 2007) [#8]
Most c++ compilers have better optimizations than BlitzMax, ie loop unrolling, function inlining etc. Some can even optimize for MMX/SSE.


Arowx(Posted 2007) [#9]
Hey don't forget the 80/20 rule...

80 percent of the time you don't need to optimize the code, it's only the 20% that will need enhancement and you can normally only isolate the 20% when you profile your game/system under load to see where the time is being spent/wasted!


CS_TBL(Posted 2007) [#10]
One thing that concerns me a bit is converting an image (timage) to my arrays, that takes serious time (few hundred ms for a rather small pic, up to seconds for a larger pic), that's actually crappy as the texgen could be used to modify images, mix 2 images, etc. So therefor I wished to know whether I could speed up things, but alas.