performance of some C++ apis

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Dec 2006
Posts: 36
Reputation: unclepauly is an unknown quantity at this point 
Solved Threads: 0
unclepauly unclepauly is offline Offline
Light Poster

performance of some C++ apis

 
0
  #1
Jan 6th, 2007
i am using a couple of methods to calculate the distance between any 2 points on the earths surface. the methods are the law of cosines, and the haversine formula.

the law of cosines formula uses the C++ functions acos, sin and cos, all found in math.h:

acos(sin(lat1).sin(lat2)+cos(lat1).cos(lat1).cos(long2−long1))

the haversine formula also uses sin and cos, but also atan2.

dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))2 + cos(lat1) * cos(lat2) * (sin(dlon/2))2
c = 2 * atan2(sqrt(a), sqrt(1-a))
d = R * c


does anyone know how these functions operate, and if one is more 'effiecient' than the other (ie running time). specifically i am interested in the atan2 api. is this function 'slower' than the cos and sin functions? or is it better?

i have tried to test these 2 methods by calling them in a loop for a set number of times - and they both seem to run in the same time (ish). but i dont think my tests are particularly strong. i would like some conclusive evidence that supports the performance of these maths functions - i cant find any documentation on the net concerning this.
Last edited by unclepauly; Jan 6th, 2007 at 8:20 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,454
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: performance of some C++ apis

 
0
  #2
Jan 6th, 2007
I think most math operations are performed on the math coprocessor instead of in code. So the functions are probably optimized as much as possible.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 36
Reputation: unclepauly is an unknown quantity at this point 
Solved Threads: 0
unclepauly unclepauly is offline Offline
Light Poster

Re: performance of some C++ apis

 
0
  #3
Jan 8th, 2007
ok thats cool, thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Computer Science Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC