A performance test for trigonometric functions, computed with the CORDIC method.
Starting from
Every iteration is computed via a matrix multiplication. Let
By applying the matrix multiplication repeatedly, we get the following:
Where
The product of cosines is computed, given the approximation mentioned earlier, as the infinite product
The functions implemented here are different implementations of the cosine function. The data refers to the performance on my own, rater crappy, 2015 laptop computer (Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
)
The first version uses an implementation of the atan function I found on stackoverflow to compensate for the tangent approximation. For 5000000 iterations:
execution time in seconds : 7.060013
CO-2eq: 0.014708
The second version does not compensate for the approximation at all. For 5000000 iterations:
execution time in seconds : 1.049544
CO-2eq: 0.002187
The third version uses a lookup table of atan
values. For 5000000 iterations:
execution time in seconds : 1.757478
CO-2eq: 0.003661
The first fixed point version does not compensate for the approximation. For 5000000 iterations:
execution time in seconds: 0.399688
CO-2eq: 0.000833
The second one uses a lookup table of fixed point atan
values.
execution time in seconds: 0.616319
CO-2eq: 0.001284
For reference, the standard math.h
cosine function is executed 5000000 times in just 0.016892
seconds on my setup, lol.