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

If you need optimization that badly, then make a look up table with cosine and sinus table.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.