The accuracy and speed of function approximations – part 3
In part 2 we had a look at the accuracy of the approximated functions. In this part we will take a look at the speed of the same approximated functions.
There is no reason to use approximation unless you gain something from it. Usually the gain will be in the form of a speed improvement over the real function. Embedded devices with low memory and low frequency CPU can benefit greatly from approximation – even new computers can benefit from it. Lets test it out:
The timing depends a lot on the platform and settings. This is compiled under .Net 3.5 SP1 x64 in release mode. Timing is based on 1000000 iterations.
The results are clear – the quadratic curve equation is a lot faster than both the Taylor series and real sine function. The quadratic curve equation is also more accurate than the Taylor series.
If you are programming for embedded devices such as mobile phones, PDAs or barcode readers, you can gain a lot of function approximations. In this article series we tested the accuracy (true across all platforms – small but consistent variations can occur) and the speed on the PC platform. Using a quadratic curve approximation with added accuracy can give you 10 times better performance for a small sacrifice in accuracy.
You can get the code to the approximation library (written in C#) here: Approx.net
Update: I managed to improve the performance of the LowSin() function. It now runs at 3 ms on my computer.