Function Speed Increase?

BlitzMax Forums/BlitzMax Programming/Function Speed Increase?

Chroma(Posted 2007) [#1]
Nm...it didn't work...


Chroma(Posted 2007) [#2]
Hmm...looks like I got over zealous. The function would require an argument that doesn't exist. IE arugments must be a Constant. Soooo...nm.....


H&K(Posted 2007) [#3]
So you call it with
Local AnInstance:MyType = Mytype.Create(New MyType)

As opposed to
Local AnInstance:MyType = Mytype.Create()
Which would mean you also had to take into concideration the Call functions speed.

It may be faster, It may not, however (And this is just for me), I dont have NEW in open code at all, (Yes I do see that its only a small consetion to this rule, but there you go. Also I have this as my normal setup
Function Create:MyType ()
   Return New Mytype.Allocate()
end Function
Were Allocate is doing really what your second Function is doing, but with the benifit that I have effectivle both functions you have described. (This way makes overriding easier)

I would say on a different note, that I would try and not create any object in time critical operations. This would include (say) bullets which I would not create in Loop time, but would rather already have an array of Non-displayed bullets ready (for example). So its my feeling that even if there is a slight sdeed increase in your second method, the inconvenience of haveing to add NEW to ever Create wouldnt be worth it.

It would however be interesting to find out which of the two fucntions and calls is faster


Chroma(Posted 2007) [#4]
Doh..didn't think anyone would post so I deleted my original post.

I can add some value to this post though I think. We all know multiplaction is faster than division in the FPU processor. So from now on when you have a lot of division to do, just convert it to multiplication like this:

Bad way:
a.x = b.x / s
a.y = b.y / s
a.z = b.z / s


Optimized way:
Local inv:float = 1.0 / s
a.x = b.x * inv
a.y = b.y * inv
a.z = b.z * inv


Ta da!


H&K(Posted 2007) [#5]
lol