
June 9th, 2010, 06:00 AM
#1
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(onepow(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

June 9th, 2010, 07:05 AM
#2
Re: Arc cosine calculation performance problem
isnt this equal to:
Code:
_acos = c*log(dotprods[j]+c*sqrt(one(dotprods[j]*dotprods[j])));

June 9th, 2010, 08:31 AM
#3
Re: Arc cosine calculation performance problem
Just a little faster, but they are both slow

June 9th, 2010, 08:51 AM
#4
Re: Arc cosine calculation performance problem
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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it.  P. D. Ouspensky

June 9th, 2010, 11:35 AM
#5
Re: Arc cosine calculation performance problem
Yes release mode with optimization at "Favors fast code"

June 9th, 2010, 12:19 PM
#6
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)).

June 9th, 2010, 07:24 PM
#7
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

June 10th, 2010, 05:43 AM
#8
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.

June 10th, 2010, 01:27 PM
#9
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
Tags for this Thread
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
