Is it faster to pass (float, float, float) as parameters of the vs (float[]) method, where the array has three members?
It depends. If you already have an array of floats, this should not make any difference. If you create an array each time, it will take some time for assignments to the array and, possibly, some time for building the array.
Does it matter? If you do this in a tight loop that runs several million times in a row, and many times during the life of your application, this can certainly be done.
Is it faster for a method to return float [] against setting the contents of float [], which is passed to the method as an argument?
If you need to build a float array each time for your return value, then this, of course, will not be faster than setting values ββin a pre-existing array. Just because both options include setting values, and one of them has the additional task of creating a new array. But creating a new array can be really, really fast.
However, if you do this many millions of times in your application quickly, compare it, this can save you some time.
Is it faster to replace method calls with actual calculations, i.e. instead of A=sum(B,C) less than A=B+C ? provided sum(x,y){return x+y}
It is almost impossible to say. HotSpot's built-in code optimizer is pretty good at things like this and optimizes this for yours.
If you are comparing this, try making the sum method private , which makes it easier for HotSpot to decide that it can be inlined (although it will also detect it by itself if you don't have overridden implementations of the sum method)
The only thing about benchmarking:
This can help your application right now, with the current version of the virtual machine that you are using (and the current code base). If you decide to upgrade to a new version of the virtual machine, you may find that the performance characteristics are changing and you may need to optimize again.
So do it only if it is really important for your application, otherwise it may be wasted.
It is better to first focus on your algorithm, as well as its spatial and temporal complexities; any gain is forever.