0

Hi all,

I am in the process of optimizing my code and I was wondering what the fastest way is to compute trig functions.

I profiled my code and to my astonishment discovered that one of the most time-consuming processes is computing cos(theta) and sin(theta) using the implementation of cos() and sin() in the cmath library.

Are there other libraries that function better or should I consider computing these functions as truncated Taylor series'?

I have already taken the step to ensure that these functions are only computed once for each value of theta (and then stored in a double which is used afterwards in the code), but it seems that there is a high cost involved in even computing these functions once for each value of theta (3000 times in my code right now).

Anyway help would be greatly appreciated.

Incidentally, (maybe this is common knowledge), it turned out that the most time consuming process was using the pow() function! Lesson learned for me: never use pow!

Thanks in advance,

Kartik

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by nezachem
0

Hi all,

I am in the process of optimizing my code and I was wondering what the fastest way is to compute trig functions.

libm

I profiled my code and to my astonishment discovered that one of the most time-consuming processes is computing cos(theta) and sin(theta) using the implementation of cos() and sin() in the cmath library.

What else does your code doing?

Are there other libraries that function better or should I consider computing these functions as truncated Taylor series'?

No. Taylor series is by no means optimal.

Incidentally, (maybe this is common knowledge), it turned out that the most time consuming process was using the pow() function! Lesson learned for me: never use pow!

Kartik

Show your profiles.

Edited by nezachem: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.