speed: bmax vs c++
BlitzMax Forums/BlitzMax Beginners Area/speed: bmax vs c++
(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.
Use pointers instead of arrays. Arrays have an additional indirect jump for every access, it seems.
hm.. and then? Is it then as fast as c++?
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 ;)
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?
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
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
Most c++ compilers have better optimizations than BlitzMax, ie loop unrolling, function inlining etc. Some can even optimize for MMX/SSE.
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!
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.