Cpu is fast and disk is cheap. This is our mentality nowadays. But that can be wrong, and even it's true, it's still good to think about optimization.
here's a simple benchmark of some operations: (if it's not aligned, not totally my fault:)
CPU: Intel Pentium4 with HyperThreading dL1:16KB dL2:1024KB
Benchmark Time(ns) CPU(ns) Iterations
------------------
BM_FloatDivide 10 10 100000000
BM_DoubleDivide 12 12 100000000
BM_Tanf 87 85 100000000
BM_Tan 99 99 100000000
BM_Sinf 54 54 100000000
BM_Sin 53 53 100000000
BM_Cosf 52 52 100000000
BM_Cos 59 59 100000000
....
So, how to optimize those computationally-cost operations?
1. Lookup Table is always a choice if you know the input range and the resolution.
2. Taylor (or other) expansion is also a good choice
Example:
Tan(x) can be replaced by (1/(0.5-x) - 1/(x + 0.5))/pi : (with small difference:)
Use gnuplot:
gnuplot> plot [-0.499:0.499] tan((x)*pi), (1/(0.5-x) - 1/(x + 0.5))/pi