Alex Rivera | Logout

Calculating vs. lookup tables for sine value performance?

Asked 2009-09-05T02:57:26.273
21

Let's say you had to calculate the sine (cosine or tangent - whatever) where the domain is between 0.01 and 360.01. (using C#)

What would be more performant?

  1. Using Math.Sin
  2. Using a lookup array with precalculated values

I would anticpate that given the domain, option 2 would be much faster. At what point in the precision of the domain (0.0000n) does the performance of the calculation exceed the lookup.

Edit
Report

1 Answer

0

As you may have thousands of values in your lookup table, what you may want to do is have a dictionary, and when you calculate a value, put it in the dictionary, so you only calculate each value one time, and use the C# function to do the calculation.

But, there is no reason to recalculate the same value over and over.

answered 2009-09-05T13:28:32.427

Your Answer