Possible Duplicate:
How do Trigonometric functions work?
What actually goes into the computation of trig functions like Sin, Cos, Tan and Atan?
I think I've found an optimization in my code where I can avoid using any of these functions and base the problem around slope instead of angles. So that means a couple division operations in place of the above trig functions. But I'd like to know more about what goes into those trig functions so that I can compare my new code (from the perspective of number of basic math ops). Or maybe I've just found a more circuitous way of doing the same thing, or worse, introduced a less efficient method.
Using C++ and Python but I imagine these is fairly language agnostic with math operation cost being relative to the most primitive operations.
You need to profile this yourself. Based on my results, trig functions take about 100 ns and divisions about 20 ns. That can be easily converted to answers. But again, the most important thing is that you profile this on your hardware. That way you get exactly right answers and knowledge for your system.
Modern x86 processors include trig functions in their instruction set, but they take many cycles to execute. So if you're on such a processor, and if you have no dependencies in your code (i.e. you don't need the result of one sin computation in order to start the next one), then you probably won't get much faster than using sin and cos directly, as they will be fully pipelined, achieving an effective rate of 1 per cycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With