r/programming • • Jul 20 '20

Implementing cosine in C from scratch

http://web.eecs.utk.edu/~azh/blog/cosine.html
503 Upvotes

104 comments sorted by

View all comments

Show parent comments

3

u/mttlb Jul 20 '20

It's kind of the heart of the problem and tradeoff of using lookup tables: the gains heavily depend on the context, how often they're actually used inside of a bigger program, etc. If they're slightly too big you're in for a ton of cache misses and it's a disaster. This is partially why they're only moderately used in most standard implementations, which prefer more robust and predictable (but also more complex) methods that will behave the same in most if not all cases.

3

u/yeusk Jul 20 '20 edited Jul 20 '20

That the most up voted comment here is generalizing saying not to use look up tables, without giving real benchmarks, because cache misses is embarrassing. Is the first optimization most people do when CPU bound and every game uses it in one way or another, graphics, audio, trigonometry.

I have made test.

In my case with 44100 calls per second per instance with 50 instances a Lut was 3 times faster than with sin.