| | |
performance of some C++ apis
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Dec 2006
Posts: 36
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- Performance Increase Through My Computer (Windows tips 'n' tweaks)
- Clean Your Prefetch to Improve Performance (Windows tips 'n' tweaks)
- 7 Tips to Keep your PC Running At Peak Performance (Windows tips 'n' tweaks)
- Set Performance Options in Windows XP (Windows tips 'n' tweaks)
- XP Styles or Winblinds - Performance hit? (Windows NT / 2000 / XP)
Other Threads in the Computer Science Forum
- Previous Thread: Would this system be secure?
- Next Thread: age calculator
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business cern codebreaker compiler computer computers computerscience computertrackingsoftware conversion csc data dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis dissertationtopic ebook employment energy extensions floatingpoint foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet iphone ipod itcontracts jobs kindle laser laws lsmeans mainframes marketing mining mobileapplication msaccess netbeans networking news os p2p piracy piratebay programming research sas science security sex simulation software spying sql study supercomputer supercomputing sweden technology textfield turing turingtest two'scompliment uk virus warehouse ww2






