Arc cosine calculation performance problem
In my previous post I figured out (thanks to D_Drmmr) how to calculate arc cosine with real numbers (including numbers not in the range -1;1).
Code:
_acos = -c*log(dotprods[j]+c*pow(one-pow(dotprods[j],2),0.5));
Anyway my application response times have increased by four times with this line
Is there any other way to calculate arc cosine (I am using VS2010 in a standard C++ project) faster?
Or is there any other possible engineering to make the program faster?
Thanks in advance
Re: Arc cosine calculation performance problem
isnt this equal to:
Code:
_acos = -c*log(dotprods[j]+c*sqrt(one-(dotprods[j]*dotprods[j])));
Re: Arc cosine calculation performance problem
Just a little faster, but they are both slow :(
Re: Arc cosine calculation performance problem
Quote:
Originally Posted by
pm44xl22
Is there any other way to calculate arc cosine (I am using VS2010 in a standard C++ project) faster?
Or is there any other possible engineering to make the program faster?
Are you testing with a release build? I'm not sure about VS2010, but in previous versions the default project settings did not perform full optimization. Check the project settings, most importantly those under C/C++ --> Optimization.
Re: Arc cosine calculation performance problem
Yes release mode with optimization at "Favors fast code"
Re: Arc cosine calculation performance problem
Code:
sqrt(one-(dotprods[j]*dotprods[j])));
If these were dot products of unit vectors, then dotprods[i] == cos(theta), where theta is the angle between the unit vectors.
In that specific case, this entire expression simplifies to abs(sin(theta)).
Re: Arc cosine calculation performance problem
I'll try this as solution but the logarithm still takes part. Don't know whether I can get better response times
Re: Arc cosine calculation performance problem
calculating a log() is slow. not much you can do about that.
If you're doing lots of acos calculations, then you can speed things up by making a table of acos over a certain range with a certain step and use interpolation to calculate the value of an acos() call.
Depending on needed accuracy and range, you may end up needing a very big table though.
Since you mention 'slow' I'm asuming you're calling acos() thousands/millions of times? You probably need to look at ways to remove the acos() call out of your inner loops rather than trying to optimise the acos() call itself.
Re: Arc cosine calculation performance problem
Hundreds of thousands, I think you're right and a table is the only way to speed up the process